Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 853
Digby Norris Avatar asked Jul 19 '13 21:07

Digby Norris


People also ask

How do I count my likes on Facebook?

If you ever need to re-enable the like counts, open the same “Reaction Preferences” window. In the window, toggle off both “On Posts from Others” and “On Your Posts” options. Facebook will start showing the like counts in your account.

What data can I get from Facebook graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

How do I get Facebook Page Insights on graph API?

You can access Page Insights by typing /insights after the name of your page in the URL field. This command will retrieve all of the Insights associated with your Page. Type "/insights" after your company name. Click the Submit button.

Does Facebook Graph Search still work?

In early June 2019, the feature was further deprecated, with the majority of URLs for graph search queries no longer working. Facebook explained this by saying: "The vast majority of people on Facebook search using keywords, a factor which led us to pause some aspects of graph search and focus more on improving keyword ...


1 Answers

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.

like image 85
dvk Avatar answered Sep 21 '22 01:09

dvk