3

I have the following simple example in Python 2.7 (using the Anaconda distribution) for accessing data using the Facebook Graph API:

   import facebook

    token = 'mytoken'

    graph = facebook.GraphAPI(token)
    profile = graph.get_object("me")
    friends = graph.get_connections("me", "friends")

    friend_list = [friend['name'] for friend in friends['data']]

    print friend_list

Initially I got the 'module' object has no attribute 'GraphAPI' and noticed that the prepopulated list of methods for facebook was basically empty. This led me to take the advice of this post and uninstall facebook and install facebook-sdk. This worked in the sense that now GraphAPI shows up in the prepopulated list, but I still get the following error:

AttributeError: 'module' object has no attribute 'GraphAPI'

Is there another solution to this problem I might be overlooking?

2 Answers 2

1

This is a known Problem. Just uninstall facebook and facebook-sdk and then reinstall only facebook-sdk.

GraphApi module present in pyfacebook or not

Python Facebook SDK: 'module' object has no attribute 'GraphAPI'

Update1:

I think I got it now. I think you aren't using the token. Just try this:

import facebook

token = 'mytoken'

graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")

friend_list = [friend['name'] for friend in friends['data']]

print friend_list
Sign up to request clarification or add additional context in comments.

5 Comments

Hi DevTec, I already tried that as mentioned, is this the only possible cause? I will need to get the git command working first and try the git solution to make sure I've exhausted all options.
Sorry, I've updated my post to show the use of (token), that was my mistake. I also tried installing git and using the git method described in the first link with no luck. I'm wondering if it has something to do with Anaconda not uninstalling facebook properly or something like that.
Are you using Django? Can you try it in another Environment?
I'm running it in Spyder right now, it's just a stand alone test unfortunately. UPDATE: I tried it in IPython Notebook and it seems to be working, very strange. Thanks for prompting me to test a different environment, I'll need to figure out what's wrong with Spyder.
Glad to help! I hope that you find the problem! I would be interested in the solution, maybe you could write back?
0

May be obvious, but make sure your python script isn't also named facebook.py, as it will clash with the package and cause this error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.