The temporary access token can be exchanged against a permanent access token later (s. below).
- Go to the Graph API Explorer
- Choose your Facebook-App
- Choose "User-Token"
- Add permissions as required
- Click "Generate Access Token" and give permissions
- Copy the temporary access token. This is the short-lived access token needed to generate a permanent access token.
Make sure, you have the following information ready:
Key | Description |
---|---|
USER_ACCESS_TOKEN |
a valid short-lived token (user access token) |
APP_ID |
the app id (s. app → settings → basic) |
APP_SECRET |
the app secret (s. app → settings → basic) |
Get a 'long-lived' access token.
$ curl -X GET "https://graph.facebook.com/v11.0/oauth/access_token?grant_type=fb_exchange_token&client_id={APP_ID}&client_secret={APP_SECRET}&fb_exchange_token={USER_ACCESS_TOKEN}"
{"access_token":"{ACCESS_TOKEN}","token_type":"bearer"}
Use the returned access token to get your user id.
$ curl -X GET "https://graph.facebook.com/me?access_token={ACCESS_TOKEN}"
{"name":"{NAME}","id":"{USER_ID}"}
Then use your user id and the long-lived token to get a permanent access token.
$ curl -X GET "https://graph.facebook.com/v3.2/{USER_ID}/accounts?access_token={ACCESS_TOKEN}"
{"data":[{"access_token":"{PERMANENT_ACCESS_TOKEN}"}]}