Danna Castro
Danna Castro

Reputation: 289

Get Facebook App Access Token in django

I'm trying to get my facebook app access token en my django project. 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.

Can somebody tell me what is wrong with it? Thankyou so much.

Upvotes: 0

Views: 1397

Answers (1)

Piotr Pęczek
Piotr Pęczek

Reputation: 408

If you want to connect your application with Facebook or any other social media you just don't care about tokens. Middleware does:

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

&

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

Upvotes: 1

Related Questions