How to get Likes Count when searching Facebook Graph API with search=xxx

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 03:18:01

Couldn't find this in the documentation but multiple calls to the API are not necessary. You can use summary when querying a feed or multiple posts. Specify this in the fields parameter.

https://graph.facebook.com/PAGE_ID/feed?fields=comments.limit(1).summary(true),likes.limit(1).summary(true)

This will return a response like this.

{
  "data": [
    {
      ....
      "summary": {
        "total_count": 56
      }
      ...
    }, 
    {
      ....
      "summary": {
        "total_count": 88
      }
      ...
    }
  ]
}

This will be much faster than making individual requests for each object just to get the number of comments or likes.

You can also get all Posts > Comments > Likes in a single request:

https://graph.facebook.com/<obj_id>/feed?fields=message,comments.limit(10).summary(true){message,from,likes.limit(0).summary(true)}

The braces are nested requests.

This gives the following result:

{
    "data": [
      {
        "message": "Contents of the Post"
        "id": "123456789123456789",
        "comments": {
        "data": [
          {
            "message": "Contents of the Comment",
            "from": {
                 "name": "John Doe",
                 "id": "123456789"
            },
            "likes": {
               "data": [],
               "summary": {
                  "total_count": 14,
                  "can_like": true,
                  "has_liked": false
               }
            },
       ...

The summary is on the likes connection of the post object

just call

https://graph.facebook.com/POST_ID/likes?summary=true&access_token=XXXXXXXXXXXX

there will be a 'summary' element with a 'total_count' field

To get the count of page likes you can use fan_count field.

search?q=xxx&fields=fan_count&type=page
Syed Raheem Uddin

I construct my API query like this, and it allows me to fetch a one shot query:

https://graph.facebook.com/PAGE_ID/feed?fields=comments.limit(25).summary(true),likes.limit(25).summary(true)

the api has changed. new field name is 'fan count'.

https://graph.facebook.com/PAGE_ID?fields=fan_count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!