简体   繁体   中英

Facebook Graph API get page post like count

for some reason I cannot access the like count for posts made in a page I created with the Facebook Graph API.

Here is the command I run: GET /xxxxx_xxxx?fields=likes

The return is as follows:

{ "id": "xxxxx_xxxx" }

I have enabled EVERY permission facebook allows me to get on the access token and I have switched the access token away from the user to the page (although setting it to the user doesn't help either).

On the graph API explorer it shows "likes" in the left column but it is greyed out and it says "Field is empty or disallowed by access token". I can also confirm that the post does indeed have likes and also does indeed exist.

What am I doing wrong?

?fields=likes would be the individual likes, made by single users, including their id and name - but you don't get user data from people who have not granted your app permission first.

If you only want the number of likes, then ask for the summary , using
?fields=likes.summary(1).limit(0)

You will get a structure of the following form,

 "likes": {
    "data": [
    ],
    "summary": {
      "total_count": 1234,
      "can_like": true,
      "has_liked": false
    }

( limit(0) prevents that you get any of the individual likes at all, if you don't need them, and will also prevent that there are extra, unnecessary pagination links contained in the result.)

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