我目前正在尝试使用PyFacebook来检索当前使用应用的朋友列表。使用下面的Python代码,我可以在执行登录后使用他们的名字和uid检索整个朋友列表:
# Desktop Application example
def desktop_app():
from facebook import Facebook
# Get api_key and secret_key from a file
facebook = Facebook('API_KEY','SECRET_KEY')
facebook.auth.createToken()
# Show login window
facebook.login()
# Login to the window, then press enter
print 'After logging in, press enter...'
raw_input()
facebook.auth.getSession()
info = facebook.users.getInfo([facebook.uid], ['name', 'birthday', 'affiliations','sex'])[0]
for attr in info:
print '%s: %s' % (attr, info[attr])
friends = facebook.friends.get()
friends = facebook.users.getInfo(friends[0:], ['name', 'birthday'])
for friend in friends:
if 'birthday' in friend:
print friend
if __name__=="__main__":
desktop_app()
这很棒,但现在我只需要当前使用指定API_KEY和SECRET_KEY的应用的朋友。有谁知道如何在PyFacebook中做到这一点?
答案 0 :(得分:1)
您需要检查installed
参数,例如
friends = facebook.users.getInfo(friends[0:], ['name', 'birthday','installed'])
for friend in friends:
if 'birthday' in friend:
if 'installed' in friend:
print friend