在django获取Facebook App Access令牌

时间:2015-07-30 22:19:48

标签: django facebook-graph-api

我正在尝试将我的facebook app访问令牌添加到我的django项目中。这是我的功能代码:

import json
import urllib2
import requests

def fb_update_app_token():
    app_id = MY_APP_ID
    secret = MY_APP_SECRET
    grant = '{0}/{1}'.format(app_id, secret)

    url = u'https://graph.facebook.com/oauth/access_token?' \
        u'client_id={0}&client_secret={1}&grant_type={2}'.format(
            app_id,
            secret,
            grant,
        )
    print url
    response = urllib2.Request(url)

    print "RESPONSE"
    print response
    token = json.loads(urllib2.urlopen(response).read())

    print "TOKEN"
    print token

    return token

但我的控制台输出是:

https://graph.facebook.com/oauth/access_token?client_id=app_id&client_secret=sectret&grant_type=app_id/secret
RESPONSE
<urllib2.Request instance at 0x104bcdb48>
[30/Jul/2015 17:05:31] "POST /dashboard/ajax-update-access-token/ HTTP/1.1" 500 14003

grap api响应是HTTP错误400:错误请求。

有人可以告诉我它有什么问题吗?非常感谢你。

1 个答案:

答案 0 :(得分:1)

如果您想将自己的应用程序与Facebook或任何其他社交媒体相关联,那么您就不必关心令牌。中间件确实:

http://django-social-auth.readthedocs.org/en/latest/configuration.html

&安培;

http://django-social-auth.readthedocs.org/en/latest/backends/facebook.html