How to generate FB page access token

Posted By : Deepak Rawat | 28-Dec-2015

Ever wondered how to generate FB page access token, here is how. Used in graph API calls to manage Facebook pages. Admin of page must grant extended permission called manage_pages, for generate page access token.

You can retrieve page access token, once this permission has been granted using following graph API request :

HTTP

 GET /me/accounts HTTP/1.1
Host: graph.facebook.com
 

 

PHP SDK

 $request = new FacebookRequest(
  $session,
  'GET',
  '/me/accounts'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
 

 

JavaScript SDK

 FB.api(
    "/me/accounts",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
 

 

Android SDK

 new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/me/accounts",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
 

 

iOS SDK

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/me/accounts"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];
 

 

You can use this type of token to make API calls on behalf of page. For example, you can post status update to page or read page insights data.


Page access token are unique are unique to each admin, page and application.

 

THANKS

About Author

Author Image
Deepak Rawat

Deepak is a Web and Mobile application Sr. Lead Frontend developer and good working experience with JQuery , AngularJS , Javascript and PhoneGap. His hobbies are listening to music and photography.

Request for Proposal

Name is required

Comment is required

Sending message..