我facebook.py使用來自: https://github.com/pythonforfacebook/facebook-sdk需要列出所有的朋友facebook.py
我的問題是: 我不知道下次使用的URL從graph.get_object(「我的/朋友「)
graph = facebook.GraphAPI(access_token)
friends = graph.get_object("me/friends")
我facebook.py使用來自: https://github.com/pythonforfacebook/facebook-sdk需要列出所有的朋友facebook.py
我的問題是: 我不知道下次使用的URL從graph.get_object(「我的/朋友「)
graph = facebook.GraphAPI(access_token)
friends = graph.get_object("me/friends")
如果您在/me/friends
鍵入到Graph API Explorer,你會看到它返回一個JSON文件,它僅僅是一個字典和列表內彼此的組合。
例如,該輸出可以是:
{
"data": [
{
"name": "Foo",
"id": "1"
},
{
"name": "Bar",
"id": "1"
}
],
"paging": {
"next": "some_link"
}
}
此JSON文件已經轉換爲Python字典/列表。在外部詞典中,密鑰data
映射到包含關於朋友的信息的詞典列表。
所以,打印您的好友列表:
graph = facebook.GraphAPI(access_token)
friends = graph.get_object("me/friends")
for friend in friends['data']:
print "{0} has id {1}".format(friend['name'].encode('utf-8'), friend['id'])
的.encode('utf-8')
是正確地打印出特殊字符。
Hello.And如果我喜歡那些說「喜歡」頁面的人的列表,而不是個人頁面。謝謝 – virtualsets 2014-11-02 20:21:33
如何獲得下一頁? – thekindlyone 2014-12-20 13:38:42
@thekindlyone,它是一個URL,所以你可以點擊或複製/粘貼到該URL。 – Veech 2014-12-21 02:18:34
這是一個非常好的工具,可以混淆並學習Graph API https://developers.facebook.com/tools/explorer/ – mika 2013-03-05 21:17:48