Get Facebook Page likes count via PHP with access_token

Today I had to figure out how to fetch again Facebook Page likes via PHP. Friends from FB changed the API and it was now saying An access token is required to request this resource. for the old API call. Accessing the data requires access_token from now on. Reading the docs https://developers.facebook.com/docs/graph-api/reference/page#Reading I found that a page access token exists.

How to get that page access token?

First you gonna need your FB id, visit https://developers.facebook.com/tools/explorer?method=GET&path=me& (should be the first id) Next you need to grab via API call /YOUR_FB_ID/accounts https://developers.facebook.com/tools/explorer?method=GET&path=YOUR_FB_ID%2Faccounts& After this magic should happen and you should see access_tokens for pages you manage. Now with the access token you can get data via the following URL https://graph.facebook.com/v2.3/FB_PAGE_ID?access_token=PAGE_ACCESS_TOKEN The output is a json which you can decode with PHP function json_decode().

UPDATE
I’ve got the following message: Error validating access token: Session has expired on Saturday, 20-Jun-15 00:00:00 PDT.
Token expired :/ You can check yours at https://developers.facebook.com/tools/debug/accesstoken?q=
I made a never expiring page access token thanks to https://www.rocketmarketinginc.com/blog/get-never-expiring-facebook-page-access-token/

FB neves expiring page access token

Advertisements