需要用facebook.py列出所有的朋友 [英] need to list all friends with facebook.py
问题描述
我使用facebook.py从:
https://github.com/pythonforfacebook/facebook -sdk
i use facebook.py from: https://github.com/pythonforfacebook/facebook-sdk
我的问题是:
我不知道要使用graph.get_object的下一个url(我/朋友 )
my problem is: I don't know to use the next-url from graph.get_object("me/friends")
graph = facebook.GraphAPI(access_token)
friends = graph.get_object("me/friends")
推荐答案
如果您输入 / me / friends
进入 Graph API Explorer ,你会看到它返回一个JSON文件,它只是一个字典和列表的组合。
If you type in /me/friends
into the Graph API Explorer, you'll see that it returns a JSON file, which is just a combination of dictionaries and lists inside one another.
例如,输出可以是:
{
"data": [
{
"name": "Foo",
"id": "1"
},
{
"name": "Bar",
"id": "1"
}
],
"paging": {
"next": "some_link"
}
}
此JSON文件已转换为Python字典/列表。在外部字典中,密钥数据
映射到包含有关您的朋友的信息的字典列表。
This JSON file is already converted to a Python dictionary/list. In the outer dictionary, the key data
maps to a list of dictionaries, which contain information about your friends.
所以打印你的朋友列表:
So to print your friends list:
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')
是正确打印出特殊字符。
The .encode('utf-8')
is to properly print out special characters.
这篇关于需要用facebook.py列出所有的朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!