Skip to content

Instantly share code, notes, and snippets.

@rekomat
Last active September 28, 2021 07:45
Show Gist options
  • Save rekomat/fa3e9b9de1f20d3d6bee18a84b5092e8 to your computer and use it in GitHub Desktop.
Save rekomat/fa3e9b9de1f20d3d6bee18a84b5092e8 to your computer and use it in GitHub Desktop.

Facebook Graph API Cheatsheet

Access Token

Generate temporary access token

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.

Generate 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}"}]} 

Source Get a Permanent Facebook page Access Token

Tools/Utils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment