Please disable your adblock and script blockers to view this page

Search this blog

Thursday 2 March 2017

Generate permanent Facebook Page Access Token to access Graph API


Hello All,
Hope you are doing well

Earlier I have posted about using facebook graph api to get profile information, post status on facebook timeline and post as facebook page.

To Access Facebook graph API we need to use Access Token and each access token has it's expiry time (temporary access tokens) but to build an application we need a permanent access token so that our app doesn't stop working after a time and it is not very easy to get a permanent access token , there are some steps you need to follow to get one



Create a simple Website Facebook App (If you don't have one)


Go to Register and Configure an App and learn how to create a app then go to All Apps and add a new app

Generate Short lived Access Token


Select the app from application dropdown list


Click on Get Token --> Get User Access Token , In select permissions popup check manage_pages and click Get Access Token
Now you can see short lived access token appears in Access Token field


Generate Long lived Access Token


For this we need AppId and App Secret, Go to My Apps page and Open App and copy AppId and App Secret


Now make a GET request from your browser to get long lived access token

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=short_lived_token

it'll return a long lived access token, 



you can check it's expiration time in Access Token Debugger 

Generate Permanent Access Token


Make a GET request to 

https://graph.facebook.com/v2.8/me/accounts?access_token=long_lived_access_token

It'll return a array of data[] that has permanent access token for all pages that you manage

Cheers :) Happy Learning

1 comment :