Getting my wall posts or friends from Facebook - lists are empty

1k views Asked by At

I performed following:

  1. installed 2 kinds of the Facebook APIs: pip install facebook and pip install fb

  2. Went to https://developers.facebook.com/tools/access_token/, registered my app and got User Token (some long string, used currently as hardcoded in the code, I'll change it later)

  3. Created the following code (please see comments what and how works or doesn't:

    import re
    import urllib2
    import requests
    import facebook
    import fb
    
    
    token="User Token"
    graph = facebook.GraphAPI(token)
    profile = graph.get_object("me")   #POSITIVE: I can get profile info
    friends = graph.get_connections('me', "friends")  #POSITIVE: I can get real friends count, NEGATIVE - the list itself is empty
    posts = graph.get_connections('me', "posts")  #NEGATIVE - the list itself is empty, no count is returned, as in "friends" case
    feed= graph.get_connections('me', "feed")  #NEGATIVE - the list itself is empty, no count is returned, as in "friends" case
    
    fb1=fb.graph.api(token)
    profile = fb1.get_object(cat='single', id="me")  #NEGATIVE - error in given parameters
    

To be sure I used also https://developers.facebook.com/tools/explorer with the same token and got the same results:

GET me\friends:
{
  "data": [
  ],
  "summary": {
    "total_count": 575
  },
}

GET me\feed:
{
  "data": [
  ],
}

Why the returned lists are empty?

Thanks!

Update: I found that I have no permissions, only those. How to get more? and why with permission "friends" I can't see info about them, but only total number of them?

{
  "data": [
    {
      "permission": "user_friends",
      "status": "granted"
    },
    {
      "permission": "public_profile",
      "status": "granted"
    }
  ],
}

Resolved: I found where the problem! I didn't get app token with all permissions. Perform the following:

  1. Go to the https://developers.facebook.com/tools/explorer

  2. Choose your APP name (my is lj_for_me in attached image)

  3. Press "Get User Token" and check all boxes (or what you really need).

Now you APP will have permission to get post and photos and etc from YOUR FB account. For getting the same from other users accounts you need to get such permission from FB (as far as I understood, but I did not enter too deep into this subject)

enter image description here

1

There are 1 answers

4
andyrandy On

Since v2.0 of the Graph API, you can only get friends who authorized your App with the user_friends permission too, for privacy reasons. You only get the total_count if none of your friends authorized the App.

Access to wall posts is possible with the user_posts permission, btw.