简体   繁体   English

在Django中获取Facebook应用访问令牌

[英]Get Facebook App Access Token in django

I'm trying to get my facebook app access token en my django project. 我正在尝试在django项目中获取我的facebook应用访问令牌。 This is my function code: 这是我的功能代码:

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

But my console output is: 但是我的控制台输出是:

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

And the grap api response is HTTP Error 400: Bad Request. 而grap api响应是HTTP错误400:错误请求。

Can somebody tell me what is wrong with it? 有人可以告诉我这是怎么回事吗? Thankyou so much. 非常感谢。

If you want to connect your application with Facebook or any other social media you just don't care about tokens. 如果您想将您的应用程序与Facebook或任何其他社交媒体建立连接,那么您根本就不需要令牌。 Middleware does: 中间件可以:

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

&

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM