简体   繁体   中英

Facebook Python API friends paging next returns empty array

I was just messing up with the Facebook python API.

I was trying to list all of my friends.

Here's the code :

friends = graph.get_connections("me","friends")

while(friends['data']):
   for friend in friends['data']:
        allfriends.append(friend['name'])
   try:
        friends=requests.get(friends['paging']['next']).json()
   except KeyError:
       print "Key Error"

print allfriends

This code just lists couple of my friends. When I try to make a request to the url in [paging][next], it simply returns an empty array.

I am unable to understand, as to where am I going wrong? The next url should retrieve the next set of names from the friendlist I belive.

Kindly help.

Thank You

You may want to try the following:

friends = graph.get_connections("me","friends")

while(friends['data']):
    try:
        for friend in friends['data']:
            allfriends.append(friend['name'])
        friends=requests.get(friends['paging']['next']).json()
    except KeyError:
       print "Key Error"
print allfriends

This is a better way of getting the correct data through Facebook Graph.

https://graph.facebook.com/v2.2/me/friends

The above url will only only return any friends who have used (via Facebook Login) the app making the request. Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM