Python - Facebook API - Need a working example

后端 未结 1 1669
南方客
南方客 2020-12-22 16:48

Ok, so i\'ve googled around, i\'ve found threads here on stackoverflow and i\'ve checked the official Facebook wiki and.. and what not..

I now hope that one of you g

相关标签:
1条回答
  • 2020-12-22 17:44

    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
    
    0 讨论(0)
提交回复
热议问题