Refresh Access Token in Facebook API

Tiempo de lectura: 2 minutos

html
Copy code
Reading Time: < 1 minutes

Today, we’re going to learn how to refresh the Facebook API token.

To refresh it, we’ll use the Facebook library.

pip install facebook-sdk

And this code:

def get_user_token(app_id, app_secret):
    graph = facebook.GraphAPI()
    token = graph.get_app_access_token(app_id, app_secret)
    return token

If we need to extend the current token, we will have to use this function. Remember that you need to provide a valid app token, so I recommend using it whenever a call is made:

def get_token(app_id, app_secret, access_token):
    link = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=" + app_id +"&client_secret=" + app_secret + "&fb_exchange_token=" + access_token
    s = requests.Session()
    token = s.get(link).content
    token = json.loads(token)html
Copy code
Reading Time: < 1 minutes

Today, we're going to learn how to refresh the Facebook API token.

To refresh it, we'll use the Facebook library.

pip install facebook-sdk

And this code:

def get_user_token(app_id, app_secret):
    graph = facebook.GraphAPI()
    token = graph.get_app_access_token(app_id, app_secret)
    return token

If we need to extend the current token, we will have to use this function. Remember that you need to provide a valid app token, so I recommend using it whenever a call is made:

def get_token(app_id, app_secret, access_token):
    link = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=" + app_id +"&client_secret=" + app_secret + "&fb_exchange_token=" + access_token
    s = requests.Session()
    token = s.get(link).content
    token = json.loads(token)
    token = token.get('access_token')
    return token

This way, we will refresh the Token. Remember that you should obtain app_id and app_secret as explained here: https://devcodelight.com/?p=6087

html
Copy code

(no incluyas el Tiempo de lectura). Devuelvelo directamente en formato HTML. No escribas ninguna frase añadida. Cuando termines añade un PIPE al final.

Leave a Comment