Facebook Access Tokens

The Facebook Pages Managed Source implementation follows the requirements for Facebook access tokens and will use any type of valid access token.

Which Facebook Access Token Is Right For You?

User Access Token is the best choice for obtaining access to localized and age-restricted content. The type of localization and the age restrictions applied by Facebook will depend on the location and the age of the user who creates the User Access Token.

User Access tokens expire after two months, but they offer less strict location and age restrictions. For example, when a User Access Token is created by a US-based user of legal age she or he will be able to receive interactions related to Facebook Pages that promote alcoholic beverages in the USA.

App Access Token is the best choice when you want to filter for the interactions related to Facebook Pages that are not subject to location or age restrictions. App Access tokens never expire, but they will not give you access to Facebook Pages that impose location or age restrictions. Because they are not tied to a particular person, you can share them with trusted users, administrators.

We recommend that you only use User Access and App Access tokens with DataSift Managed Sources, because Page Access tokens are limited to a single page and as such are not very useful for filtering for data from more than one Facebook Page resource. Also, Page Access tokens share their rate limit with User Access tokens.

Obtaining access tokens

Using the DataSift dashboard

You can use the DataSift dashboard to set up a Facebook Pages managed source obtaining a user token in the process.

The process is explained in our Activate Facebook Pages Managed Source guide.

DataSift does not store your password or email address, but will store the User Access Token returned by Facebook. The token can be later obtained via a call to /source/get and reused in requests sent to /source/create and /source/update.

Using the Facebook API

Obtaining a Facebook User Access Token

You can use the Facebook API yourself to obtain a user access token. Facebook provides their own information about that process and there is more than one way of doing it.

If you obtain a token from the Facebook API, make sure you obtain a 2 month access token.

One way to obtain an access token is as follows:

  1. Log in to Facebook.
  2. Go to the Facebook Developer App.
  3. Click on the Add a New App button.
  4. Type the name of your new app into the Display Name text field. Enter a contact email address and select a Category for your app.
  5. Click on the Create App ID button.
  6. Perform any security checks that are requested.
  7. Open Facebook Graph API Explorer in a new window.
  8. Select the name of your App from the Application drop-down menu.
  9. Click on the Get Token drop down, and select Get User Access Token.
  10. Click Get User Access Token on the next dialog.
  11. Copy the string of text shown in the Access token text field.

    This User Access Token expires in an hour, which makes it of limited use for our purposes. Fortunately, you can extend it.

  12. Replace the 1-hour token with a 2-month token:

    The token extension request can be made using a web browser or a command like curl. For example, if your App ID is 012345678901234 and you App Secret is 01234567890abcdef01234567890abcdef and the 1-hour token is ABC the URL you need to send your request to would be:

    https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token& client_id=012345678901234&client_secret=01234567890abcdef01234567890abcdef&fb_exchange_token=ABC

    The access token you receive now will be valid for two months.

Obtaining a Facebook App Access Token

If you'd like to use an app access token, you will need to obtain a time-unlimited App Access Token.

Facebook provides their own information about that process and there is more than one way of doing it.

One way to obtain an access token is as follows:

  1. Log in to Facebook.
  2. Go to the Facebook Developer App.
  3. Click on the Add a New App button.
  4. Type the name of your new app into the Display Name text field. Enter a contact email address and select a Category for your app.
  5. Click on the Create App ID button.
  6. Perform any security checks that are requested.
  7. Copy the value of the App ID and App Secret settings for your new app.
  8. Make a request to the Facebook Graph API using the App ID and App Secret in the request.

    The request can be made using a web browser or a command like curl. For example, if your App ID is 012345678901234 and you App Secret is 01234567890abcdef01234567890abcdef the URL you need to type into your browser would be:

    https://graph.facebook.com/oauth/access_token?client_id=012345678901234&client_secret=01234567890abcdef01234567890abcdef&grant_type=client_credentials

Notes On Facebook Access Tokens

  1. We recommend that you only use User Access and App Access tokens, because Page Access tokens are limited to one page and as such are not very useful for filtering for data from more than one Facebook Page.
  2. If you already have a Facebook Pages Managed Source that uses an App Access Token you would like to reuse, call /source/get to retrieve it as you would retrieve a User Access Token.
  3. You can always check if your token is valid using the Facebook Graph API Explorer. Paste your key into the field next to the Debug button and click on the Debug button.
  4. Facebook Graph API Explorer can be used to verify token expiry time.