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?
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
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