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?

Community
  • 1
  • 1
114
  • 876
  • 3
  • 25
  • 51

2 Answers2

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
Community
  • 1
  • 1
DevTec
  • 307
  • 3
  • 14
  • 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. – 114 Jan 16 '15 at 18:11
  • 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. – 114 Jan 16 '15 at 18:40
  • Are you using Django? Can you try it in another Environment? – DevTec Jan 16 '15 at 18:57
  • 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. – 114 Jan 16 '15 at 18:59
  • Glad to help! I hope that you find the problem! I would be interested in the solution, maybe you could write back? – DevTec Jan 16 '15 at 19:16
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.

Rafters
  • 134
  • 4