2013-06-05 82 views

回答

0

您需要有效的access_token和到/me/friends

一個Graph API調用此API文檔在https://developers.facebook.com/docs/reference/api/user/#friends

不知道列舉了Django的模塊,您正在使用或是否有穩定的一個在那裏,但以下是facepy github.com/ jgorset/facepy

import web 
from facepy import GraphAPI 
from urlparse import parse_qs 

url = ('/', 'index') 

app_id = "YOUR_APP_ID" 
app_secret = "APP_SECRET" 
post_login_url = "http://0.0.0.0:8080/" 

class index: 
    def GET(self): 
     user_data = web.input(code=None) 
     code = user_data.code 

if not user_data.code: 
    dialog_url = ("http://www.facebook.com/dialog/oauth?" + 
           "client_id=" + app_id + 
           "&redirect_uri=" + post_login_url) 

    return "<script>top.location.href='" + dialog_url + "'</script>" 
else: 
    graph = GraphAPI() 
    response = graph.get(
     path='oauth/access_token', 
     client_id=app_id, 
     client_secret=app_secret, 
     redirect_uri=post_login_url, 
     code=code 
    ) 
    data = parse_qs(response) 
    graph = GraphAPI(data['access_token'][0]) 
    friends_data = graph.get('me/friends') 

if __name__ == "__main__": 
    app = web.application(url, globals()) 
    app.run()