Get page access token with Facebook API 5.0 PHP

S. Délas picture S. Délas · Sep 30, 2015 · Viewed 21.2k times · Source

I need to post messages on a Facebook page. Specifically I want to post via cron.

Here's what the API docs say:

Page Access Token – These access tokens are similar to user access tokens, except that they provide permission to APIs that read, write or modify the data belonging to a Facebook Page. To obtain a page access token you need to start by obtaining a user access token and asking for the manage_pages permission. Once you have the user access token you then get the page access token via the Graph API.

How I can obtain a user access and page access token without a page callback? Is this possible?

Answer

luschn picture luschn · Oct 3, 2015

What you need it an Extended Page Token, it is valid forever. You get one like this:

  • Authorize with the manage_pages permission (and publish_pages if you want to post as Page later), to get a User Token
  • Extend the User Token
  • Use /me/accounts?fields=access_token with the Extended User Token to get a list of all your Pages with Extended Page Tokens - or use /page-id?fields=access_token to get an Extended Page Token for a specific Page

Information about all Tokens and how to extend the User Token: