Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...