Search code examples
jsonfacebook-access-tokenfacebook-pagefacebook-graph-api-v2.2

Generate long-lived access token for Facebook Graph API?


How would I go about generating a long-lived access token for Facebook Graph API so that I can access the JSON data of any Facebook page?


Solution

  • You can use an App Access Token that is valid forever. The downside is that you will not get data from restricted Pages (by age or country). For that, you would have to use a User Access Token. An Extended User Access Token is only valid for 60 days though. Extended Page Tokens are valid forever, but you can only generate them for Pages you own.

    You can create an App Access Token easily by just combining your App ID and App Secret, this would be it in PHP:

    $accessToken = $appId . '|' . $appSecret;
    

    How to generate all the different Access Tokens is explained in detail in the following articles: