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

facebookfacebook-graph-apifacebook-like

I am currently using Facebook graph api search to search posts as

http://graph.facebook.com/search?q=iwatch&type=post&access_token=xxxxx 

It returns in JSON format fields and use to include the like:count for a given post.

After reading the dev roadmap (https://developers.facebook.com/roadmap/) for changes after July 10th I am instructed to use the summary=true param but I have no idea how to get this to work with search?

From FB blog on roadmap.

Removing 'count' from 'comments' Graph API connection We are removing the undocumented 'count' field on the 'comments' connection in the
Graph API. Please request {id}/comments?summary=true explicitly if
you would like the summary field which contains the count (now called
'total_count')

I have tried various combinations and searched for examples but no dice. Can anyone give me some advice on how to get the new summary=true to work within a search URL for searching posts?

Best Answer

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.

Related Topic