Skip to Content

How do I get a permanent access token for my Facebook page?

How do I get a permanent access token for my Facebook page?

Getting a permanent access token for your Facebook page allows you to access the page data through the Facebook Graph API without having the token expire. This is useful for building apps and services that need ongoing access to a Facebook page.

What is an Access Token?

An access token is a string of characters that allows an app or service to make requests to the Facebook API on behalf of a specific Facebook account. It allows the app to access data from that Facebook account.

There are several different types of Facebook access tokens:

  • User access tokens – for accessing a user’s personal Facebook account
  • Page access tokens – for accessing a Facebook Page
  • App access tokens – for accessing app-level data

Page access tokens are what you need to access data from a Facebook Page via the Graph API.

Why Get a Permanent Page Access Token?

By default, page access tokens expire after a short time. This means your app would stop working after the token expires.

A permanent page access token does not expire, so it allows ongoing access to the Page as long as your app needs it. This is essential for apps, dashboards, or other services that need to access a Facebook Page on an ongoing basis.

How to Get a Permanent Page Access Token

Here are the steps to get a permanent access token for a Facebook Page:

  1. Get a short-lived page access token
  2. Extend the page access token to a long-lived token
  3. Extend the long-lived page access token to a permanent page access token

Let’s go through each of these steps in more detail:

1. Get a Short-Lived Page Access Token

To get started, you need to obtain a short-lived page access token for your Page. This token will be valid for about 1-2 hours.

There are two ways to get a short-lived page access token:

  • Using the Graph API – Make a GET request to the Graph API endpoint /page-id?fields=access_token. This will return a page access token in the response.
  • Using the Access Token Tool – Use the Access Token Tool and select ‘Get Page Access Token’ to get a token for your Page.

Make sure to select a Page that your app has permission to access. You will need to be an admin of the Page to get a page access token.

2. Extend Page Access Token to Long-Lived

Once you have a short-lived page access token, you need to extend it to a long-lived token. A long-lived token will be valid for about 60 days.

To extend the token, make the following Graph API call:


GET /{page-id}?
fields=access_token&
access_token={short-lived-token}

The {short-lived-token} is the access token you obtained in Step 1.

The response from this API call will contain a new page access token in the access_token field. This long-lived token will be valid for about 60 days.

3. Extend to Permanent Page Access Token

Once you have a long-lived page access token, you can finally extend it to a permanent token that does not expire:


GET /{page-id}?
fields=access_token&
access_token={long-lived-token}

Make this API call once more, using the long-lived token from Step 2.

The access_token returned in the response will be a permanent page access token that your app can use indefinitely, as long as the Page and app are still active.

Using the Permanent Page Access Token

Once you have the permanent page access token, you can persist it in your app and use it to make Graph API calls.

For example, to fetch the Page’s feed:


GET /{page-id}/feed?access_token={permanent-page-access-token}

The permanent token allows you to make any Graph API calls your app needs on behalf of the Page, without the token ever expiring.

Some things to keep in mind when using a permanent page access token:

  • Store it securely – treat it like a password and don’t expose it publicly
  • Set up error handling in your app in case the token ever stops working
  • Tokens can be revoked manually in App settings on Facebook

Revoking Access

If you ever need to revoke access for an app, you can do so in the App’s settings on Facebook:

  1. Go to the Facebook Page
  2. Click Settings at the top
  3. Click Apps in the left sidebar
  4. Click the app name
  5. Click Remove App

This will revoke all access tokens for that app, including any permanent page access tokens.

Conclusion

Getting a permanent access token allows ongoing API access to a Facebook Page for your app or service. Follow the steps to upgrade a short-lived token to a long-lived token and then a permanent token.

Be sure to store the permanent token securely and handle any errors gracefully in your app in case it stops working. Using the token in your Graph API calls will provide stable API access to the Page without dealing with expiring tokens.

Summary

Here is a quick summary of the steps to get a permanent page access token:

  1. Get short-lived token with Access Token Tool or Graph API
  2. Extend to 60-day long-lived token using Graph API
  3. Extend long-lived token to permanent token using Graph API
  4. Store permanent token and use for Graph API calls

Following this process will provide your app or service with permanent API access to a Facebook Page.

Access Token Type Duration
Short-Lived 1-2 hours
Long-Lived 60 days
Permanent Until revoked

This table summarizes the lifespan of the different access token types.

Getting a permanent token for your Facebook page enables stable API access for your app. Follow the steps outlined here to get a token that never expires!

Here are some additional tips on working with Facebook APIs and access tokens:

Validate Tokens Before Use

Always validate an access token before making Graph API calls. Make a simple API call like GET /me to verify the token works.

Handle Expired Tokens

Add error handling in your app code to detect expired tokens by checking error codes. Retry the token exchange steps if needed.

Rotate Long-Lived Tokens

Rotate long-lived tokens before they expire by generating new 60 day tokens periodically.

Manage Tokens Securely

Treat access tokens like passwords and store them securely. Never expose them publicly in client-side code.

With a bit of token management, you can build stable integrations with the Facebook APIs. Permanent page tokens are a powerful tool for ongoing Page API access.

Hope this guide helps you get the permanent access you need! Let me know if you have any other questions.

Facebook also provides additional resources to reference:

Consult these for more technical details on access tokens and debugging API calls.

Getting page access tokens can seem complicated at first, but this guide outlines the key steps. With a permanent never-expiring token, you can build stable long-running apps that interface with the Facebook Graph API.

Let me know if you have any other questions as you work on your Facebook API integration! I’m happy to provide more technical details and code samples.