4

How can I get fan page likes count using graph api? Earlier it was here:

https://graph.facebook.com/FANPAGE_ID/?access_token=ACCESS_TOKEN

but now it's return only:

{
   "name": "Fanpagename",
   "id": "0000000000"
}
user3115655
  • 109
  • 1
  • 2
  • 8

2 Answers2

8

For the graph api version 2.7, the term to get likes count is changed, Now you will have to write

https://graph.facebook.com/FANPAGE_ID?access_token=ACCESS_TOKEN&fields=name,fan_count

FANPAGE_ID can be the username or the page_id of any fb page. ACCESS_TOKEN must be replaced with access token.

stackMonk
  • 1,033
  • 17
  • 33
  • If i am fetching this information pragmatically for a public page. How to generate the access token on the fly? I cannot use any user Id, as it would be run by a cron at back-end. – Sonal Feb 08 '17 at 02:05
  • 1
    if you are requesting server side then, create an app on fb and use app_ID|app_token as your access token, you can use it as long as you do not hit the threshold requesting limit – stackMonk Feb 08 '17 at 05:05
7

You need to add the fields you want to get now:

https://graph.facebook.com/FANPAGE_ID?access_token=ACCESS_TOKEN&fields=name,likes

Serach for "Declarative Fields" in the changelog: https://developers.facebook.com/docs/apps/changelog#v2_4

Edit: Since v2.7 of the Graph API, "likes" has been renamed to "fan_count". More information: https://developers.facebook.com/docs/apps/changelog

The would be the new API call:

https://graph.facebook.com/FANPAGE_ID?access_token=ACCESS_TOKEN&fields=name,fan_count
Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130