azr*_*n92 4 facebook facebook-access-token
我正在为学校做一个项目,我必须得到我所有的朋友数据,以及我朋友的一些朋友的朋友数据,以便制作一张图表.为此,我计划使用facepy,但为了做到这一点,我需要一个访问令牌.我的问题是如何获得此访问令牌?
facepy
本身并不包含OAuth流程的方法
https://github.com/jgorset/facepy/issues/22
您需要使用自己的方法或外部库,以便通过Web应用程序引导用户.
例如使用web.py
,并facepy
获得me/posts
与read_stream
许可
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/"
user_data = web.input(code=None)
if not user_data.code:
dialog_url = ( "http://www.facebook.com/dialog/oauth?" +
"client_id=" + app_id +
"&redirect_uri=" + post_login_url +
"&scope=read_stream" )
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])
graph.get('me/posts')
Run Code Online (Sandbox Code Playgroud)
有关详情,请参阅
*Facebook API - 用户帖子:http://developers.facebook.com/docs/reference/api/user/#posts
*用Python发布Facebook照片 - 基本款:http://philippeharewood.com/facebook/publish -a-facebook-photo-in-python-the-basic-sauce /
*Facebook和Python - The Basic Sauce:http://philippeharewood.com/facebook/facebook-and-python-the-basic-sauce/
归档时间: |
|
查看次数: |
4377 次 |
最近记录: |