Facebook Python API 朋友分页下一个返回空数组
我刚在玩Facebook的Python接口。
我想列出我所有的朋友。
这是我的代码:
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]里的网址时,它只是返回了一个空数组。
我搞不懂我哪里出错了?我认为下一个网址应该能获取到朋友列表中的下一个名字。
请帮帮我。
谢谢你
2 个回答
0
0
你可以试试下面的方法:
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 Graph获取正确数据的更好方式。