Facebook Long Term Access Token

As part of building the social wall plugin I needed to create a way to connecting to Facebook via the SDK and get the information from a page without having to go through the difficult process of oAuth (that process will eventually be explored).

To do this and allow the social wall pull in the information I needed I had to get a never expiring access token. This took me quite a while to figure out due to the lack of detailed explanation on Facebook’s docs and other places i’d reviewed online. After exhausting all online resources, here is how I eventually got a never expiring Facebook Page Access Token.

An important note: Ensure you are the manager/admin of the Facebook page you want a get a never expiring token for, without that you’re just wasting your time.

Step 1

Log into https://developers.facebook.com/apps/ with your personal Facebook account then create a Facebook APP or use one you have already created.

Step 2

Write down that Facebook APP’s ID and application secret and get a short-lived access token from the Facebook Graph API Explorer.

On the page you need to select your app from the application dropdown — by default this will be Graph API Explorer.

Step 3

Once you have selected your desired app click the Get Access token button and choose the page you want to get an access token for. (You may be asked for permission, if you do a popup will appear, click on extended permissions and check box for manage_pages — then click get access token).

This will give you an Access Token in the Access Token box. I copied that down and tested it with the Facebook Access Token Debugger to see how quick that would expire and it should expire in less than 1 hour. In some cases you are given the opportunity to extend this to a 60 day expiration from the debugger, allowing you to skip  the steep below.

Step 4

I then took that Access Token, the APP’s Id and Application Secret and plugged those into this URL

https://graph.facebook.com/oauth/access_token?client_id=APP_ID_HERE&client_secret=APP_SECRET_HERE&grant_type=fb_exchange_token&fb_exchange_token=ACCESS_TOKEN_HERE

It’s important to note that you shouldn’t put the above URL into a browser as it contain your Facebook app secret. Instead you should run this via terminal or via your server using cURL.

Step 5

That URL gave us a long-lived access token — I tested using the Facebook Access Token Debugger and got back that it expires in 2 months (60 days).

I then went to Facebook Graph API Explorer and entered the long-lived Access Token I just created into the Access Token box and hit submit. I then selected from the node box the information I wanted, which was the Access Token.

This return some JSON data which included an Access Token and the Page ID associated to it in the results. This access token should be a never expiring token. To confirm these I tested it with the Facebook Access Token Debugger and got back it never expire.

I hope you found this useful and were able to generate the never expire access token you needed. Please feel free to share the article if it helped.

Let's make something
awesome together

Get in Touch