Artur Chmaro

blog about web technologies

Permanent Facebook page access token

One of my websites has integration with Facebook. By integration, I mean that each single post submitted to the database is automatically published to the Facebook page. In order to publish anything on FB page using API, you need to have a valid access token. Facebook documentation is pretty straightforward on that topic and you should not have any troubles with obtaining the token. Problem is that those tokens are valid for 3 months which for me is not enough. Let's find out how we can generate a permanent and non-expiring token.

First of all, we need a Facebook account and app. Once you have them go to Api Explorer and choose your app from upper right corner select box. Next click Get Token and Get User Access Token and check manage_pages option.

View post on imgur.com

Now you need to visit following URL:

https://graph.facebook.com/v2.8/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={token_from_previous_step}

If everything went fine you should get a response with the access token. Copy this access token, paste it to Graph Explorer and access /me/accounts resource. Now you can copy access token from your page entity.

View post on imgur.com

Finally, you can check your final access token in the Access Token Debug tool. It should be a permanent token without an expiry date.

View post on imgur.com