Facebook Python API friends paging next返回空数组

2024-10-01 17:32:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是把Facebook的python API搞砸了。在

我试着列出我所有的朋友。在

代码如下:

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

这段代码只列出了我的几个朋友。当我试图向[paging][next]中的url发出请求时,它只返回一个空数组。在

我不明白,我错在哪里?下一个url应该从我相信的好友列表中检索下一组名字。在

请帮忙。在

谢谢你


Tags: 代码friendapiurldatagetfacebook朋友
2条回答

您可以尝试以下操作:

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

这是通过Facebook图表获得正确数据的更好方法。在

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

以上网址只会只会返回任何使用过(通过Facebook登录)应用程序发出请求的朋友。Source

相关问题 更多 >

    热门问题