Python – Facebook API – Need a working example

The unofficial fork of the python sdk is still working fine for me.

To retrieve your friends, generate an access token here:
https://developers.facebook.com/tools/access_token/

Limitations:

  • A user access token with user_friends permission is required to view
    the current person’s friends.
  • This will only return any friends who have used (via Facebook Login) the app making the request.
  • If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.

Code

import facebook

token = 'your token'

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

Leave a Comment