Skip to content

Generating Facebook access token

istewart edited this page May 29, 2018 · 10 revisions

Take a deep breath...

...

...now go.

APP_ID = application ID, located in the top toolbar on the app's homepage.

  1. Sign up as developer: https://developers.facebook.com/
  2. Create a business page: https://www.facebook.com/pages/creation/
  3. Create an app: https://developers.facebook.com/apps. The values don't matter.
  4. Activate the app by setting it to "Live" on the app's page: https://developers.facebook.com/apps/APP_ID
  5. Fill out the basic settings for the app: https://developers.facebook.com/apps/APP_ID/settings Again, the values don't matter, you just need to provide some proof of completion for approval. This also includes adding a platform for the app, which can just be a dummy URL.
  6. Submit the app for review to gain basic access for Ads Management: https://developers.facebook.com/apps/APP_ID/review-status/ You can skip this step if you just need a short-term token, but for a long-term token your app will need ads_management permission.
  7. Activate the Marketing API! Make a query using the access token from the Marketing API (generated under Marketing API > Tools; check ads_management and ads_read permissions). It doesn't have to succeed, can be something like this, where you fill in ACCOUNT_NUMBER with the account number (found here > Create Ad > look in URL for number) and ACCESS_TOKEN with the access token that you just generated.
  8. Once you make your first query, the Marketing API will be activated and you can generate a never-ending token as follows. Generate an access token with ads_management and ads_read permission: https://developers.facebook.com/apps/APP_ID/marketing-api/tools/
  9. Generate a user access token with the manage_page and publish_pages permission (click on the drop-down menu on the right and choose "Get user access token"): https://developers.facebook.com/tools/explorer/
  10. Find the user access token and click "debug": https://developers.facebook.com/tools/accesstoken/
  11. Click "extend access token" and copy the generated token.
  12. Paste the token into the "Access Token" field, and submit the call "me/accounts": https://developers.facebook.com/tools/explorer/
  13. Copy the value for the "access_token" field, paste it here: https://developers.facebook.com/tools/debug/accesstoken/, then click "debug".
  14. The token expire value should be "never". Go here: https://developers.facebook.com/tools/accesstoken/, click on "debug" for the user access token, and then click "extend access mode."

Note! When you're making API calls with this token, you need to use the ad account ID instead of your user ID, otherwise the access token won't work. You can get the ad account ID by querying for "me/adaccounts" on the Graph API, using the token from your app: https://developers.facebook.com/tools/explorer/

Old instructions

Set up account

  1. Sign up as a developer with an existing facebook account https://developers.facebook.com

  2. https://developers.facebook.com/> My Apps "Add a new app" or select an existing one

    1. You may need to ‘add a product’. If so select ‘Marketing API’
  3. Turn app status toggle from ‘in development’ to ‘on’ near the top of the page:

    1. It will prompt you to fill out a privacy policy URL and terms of service URL, also found in the ‘Settings’ tab on the left hand side. I just put some generic ones I found: websitepolicies.com/legal
    2. Also select a category while you are at it as you will need it before you can turn the app ‘on’
  4. Go to ‘App Review’ on the left hand side of the page

    1. ‘Ads Management Basic Access’ was automatically listed and enabled in my ‘Features’ under ‘Approved Items’ but otherwise you will need to ‘Start a submission’ and add it manually. TIPS: If you do not see the numerous options on the left-hand side of the page, try a different browser. I wasted hours trying to figure out where these tabs were but they would just not load in my Chrome session.

Extending token expiration date indefinitely

  1. You need a Facebook Page (to create a new one).

  2. Then, you need create a Facebook App and activate the API Market.

  3. Generate a token with ads_management and ads_read permissions.

  4. Go to https://developers.facebook.com/tools/explorer/ use your new app (first button on the right) and select "Get user access token" in the drop down. It will prompt following pop up where you can select the permissions (scopes) for the user access token: manage_page and publish_pages. Submit.

  5. Go to https://developers.facebook.com/tools/accesstoken/ - find the table with your app and on the User Token row click on the Debug button.

  6. Click on "Extend access token" and copy the new token.

  7. Now go to https://developers.facebook.com/tools/explorer/ paste your token and in the access to the API with this call me/accounts. The response will be a json and here you can find a token for every page your profile manage. So, copy the "access_token" value of your new Fb Page and go to https://developers.facebook.com/tools/debug/accesstoken/, paste the token and click on debug.

Now: your token expire value should be "never". Go to https://developers.facebook.com/tools/accesstoken/ and on user token click on "debug" and then "extend access mode".