简体   繁体   中英

How to get Facebook page total likes number with the new Graph API (v2.4)

So recently there was a update to the Facebook Graph API and now pretty much everything requires a access_token to retrieve any type of data.

Previously you could get the number of page likes by accessing the graph like so:

http://graph.facebook.com/{page-name}

But now if you try it says you need to have a access token because of a recent update to the API. Now the issue i am having is i cant access the likes even with an access token this is the response i am getting:

Request

http://graph.facebook.com/{page-name}/?access_token={access_token}

Response

array(2) {
    ["name"] "Page Name"
    ["id"] "Page Id"
} 

Now at first i thought the access token wasn't being generated with the correct scopes but i am 99% sure you only need read_stream to pull that type of data.

Second thought is that they have removed the ability to acces likes of any page and you need a page token to receive that type of data or finally i am missing something incredibly small here and its still achievable?

So my question is can you still get the number of likes of any page using the Facebook Graph API and if the answer is yes how do you do it?

any help appreciated

The Graph API v2.4 reduces the number of fields in default responses.

https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/

Fewer default fields for faster performance: To help improve performance on mobile network connections, we've reduced the number of fields that the API returns by default. You should now use the ?fields=field1,field2 syntax to declare all the fields you want the API to return.

If you do ?fields=likes it should show up.

您可以这样:

https://graph.facebook.com/v2.4/{page_id}/fields=likes

This can help you! Just add ?fields=likes after the page name/id. You can use any access token for fetching data!

graph.facebook.com/{page_name}?fields=likes&access_token={token}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM