2013-06-03 40 views
0

我目前正在嘗試使用PyFacebook檢索當前使用應用程序的朋友列表。下面的Python代碼,我可以進行登錄後獲取的與他們的名字和朋友的UID整個列表:如何使用PyFacebook檢索當前使用應用程序的朋友?

# 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中做到這一點?

回答

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 
相關問題