D
D
Dmitry2015-02-14 14:12:26
Python
Dmitry, 2015-02-14 14:12:26

How to get access_token for facebook in python?

Please tell me how to get access_token for facebook.
Tried like this:

import facebook
import requests

FACEBOOK_APP_ID     = 'XXXXXXXXXXXXXXX'
FACEBOOK_APP_SECRET = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
""" # old version
payload = {
    'grant_type': 'client_credentials',
    'client_id': FACEBOOK_APP_ID,
    'client_secret': FACEBOOK_APP_SECRET
}
file = requests.post('https://graph.facebook.com/oauth/access_token?', params = payload)
oauth_access_token = file.text.split("=")[1]
"""
oauth_access_token = "|".join([FACEBOOK_APP_ID, FACEBOOK_APP_SECRET])

graph = facebook.GraphAPI(access_token = oauth_access_token, version = '2.2')
groups = graph.get_object("me/groups")
group_id = groups['data'][1]['id']
graph.put_object(
        group_id,
        "feed",
        message = instance.text,
        link = instance.get_short_absoluteurl(),
        picture = instance.img_url_absolute
    )

As a result, I get oauth_access_token == "XXXXXXXXXXXXXXX|code_from_character_set"
And the error falls: An active access token must be used to query information about the current user.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egorsmkv, 2015-02-14
@egorsmkv

If I understood the documentation page correctly , then you need to send the request again here:

http://graph.facebook.com/endpoint?key=value&access_token=app_id|app_secret

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question