如何在python中找到facebook上的朋友的名字

时间:2015-12-14 05:51:51

标签: python facebook

我已尝试使用此代码在python中查找facebook上的朋友名称,但它无效

import facebook

token='my token'

graph= facebook.GraphAPI(token)

profile=graph.get_object("me")  #extracting your own profile

friends=graph.get_connections("me","friends")['data']

friend_list=[friend['name'] for friend in friends]

print friend_list

错误: SyntaxError:调用'打印'

时缺少括号

2 个答案:

答案 0 :(得分:6)

试试这个:)

token = 'mytoken'

graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")

friend_list = [friend['name'] for friend in friends['data']]

print friend_list

答案 1 :(得分:4)

该错误意味着您使用Python 3和Python 2中的代码,请尝试:

print(friend_list)

来源:What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?

顺便说一句,我对Python没有任何线索(我只是将错误信息插入谷歌),但如果friend_list是一个数组,你可能想尝试这样做:

print(', '.join(friend_list))

此外,如果您不知道,您只能访问使用user_friends授权您的应用的朋友。有关详细信息,请参阅此主题:Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app