How do I get the App Access Token via the Facebook PHP SDK? How do I get the App Access Token via the Facebook PHP SDK? php php

How do I get the App Access Token via the Facebook PHP SDK?


You don't really have to request an application access token. You can simply assemble one yourself.

An application access token is formatted like this:

app_id|app_secret

That's the application's id, a pipe character | and the application secret.

Make sure that this app token is not accessible to your users! Only use and reference it on the serverside - never pass this to the client. For more info, check out the last few sentences in the relevant documentation.


With version 5 of the SDK you can get the access token with the accessToken() method of a FacebookApp instance. If you have a Facebook instance (as you normally would) you can get it like this:

$fb->getApp()->getAccessToken()

When I want to use my own app's access token I'm instantiating the API like this. I don't know if there's a cleaner way.

$fb = new \Facebook\Facebook([    'default_graph_version' => 'v2.8',]);$fb->setDefaultAccessToken($fb->getApp()->getAccessToken());


Replace -

'&client_secret' => 'client_secret''&grant_type' => 'grant_type'