我正在使用 django python 制作网络服务。当我登录时,我能够获取我的朋友信息。我想知道步骤或 API,如果我传递一个 userId,它将给我他/她的公共朋友列表
问问题
224 次
2 回答
0
您需要有效的 access_token 和 Graph API 调用/me/friends
相关的 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()
于 2013-06-05T07:40:58.060 回答
0
你检查过https://pypi.python.org/pypi/facebook-sdk吗?似乎它可能会做你正在寻找的东西。
于 2013-06-05T07:41:34.787 回答