Facebook graph api comment count - facebook

seems Facebook changed the result of posts, few weeks ago it was possible to read the comment count from the post directly
https://graph.facebook.com/125909647492772_502974003098530
you got something like
...
"comments": {
"data": [
{
"id": "502974003098530_78616446",
"from": {
"name": "Mathias Fritz",
"id": "526559276"
},
"message": "saugeil!",
"can_remove": false,
"created_time": "2013-03-26T14:58:01+0000",
"like_count": 1,
"user_likes": false
}
],
"paging": {
"cursors": {
"after": "MQ==",
"before": "MQ=="
}
},
"count": 1
but now the count is missing.
I did some research on the graph documentation but the only change in that direction seems to be that comments can have comments now... and those comments are counted in a field named comment_count.
Is there still a way to get the total comment count?

To get the count, add ?summary=1 at the end: https://graph.facebook.com/125909647492772_502974003098530/comments?summary=1

I was having same problem, just adding likes.summary(true),comments.summary(true) in parameter in against "fields" worked for me.
e.g. I used https://graph.facebook.com/me/feed?access_token=ACCESS_TOKEN&fields=story,from,story_tags,likes.summary(true),comments.summary(true)
instead of https://graph.facebook.com/me/feed?access_token=ACCESS_TOKEN
Also you can add other parameters if you want; separated by a ,

summary=true is what you are looking for
Get likes count :
114916098537132_1265715836790480/likes?summary=true
Get comments count
114916098537132_1265715836790480/comments?summary=true
Get shares count :
114916098537132_1265715836790480?fields=shares
And last [ combining all 3 ]
114916098537132_1265715836790480?fields=shares,likes.summary(true),comments.summary(true)
Improved version ( add limit(0) to removes list of likes and get only summary ):
114916098537132_1265715836790480?fields=shares,likes.limit(0).summary(true),comments.limit(0).summary(true)

This works perfectly with me:
fields=shares,created_time,comments.summary(true).limit(0)
This return comments count at summary and return 0 comments at the same time which is perfect as you only need the comment count.

You can get total comment count via FQL. See this question below as reference:
Facebook API - comment count via FQL
Here's the query you need: SELECT comment_info FROM stream WHERE post_id = ...

If you'd like to count everything on Facebook.
(That number is visible for Facebook's User)
You should use FQL (Facebook Query Language) instead of Graph API.
Facebook Query Language Reference
This situation you should to query
SELECT comment_info FROM stream WHERE post_id = ...

You can do such requests:
{pageid}/posts?fields=comments.summary(1){id}
It will return a list of posts including comments count of each post.
Here I have returned only the comment id because I only need the number of comments per post, but of course you can include many other fields:
{pageid}/posts?fields=comments.summary(1){id,message},id

Or to make less changes to you excisting code, use:
$.each(json.data,function(i,fb){
...
var commentsCount = 0
if(fb.comments!=undefined){
commentsCount=fb.comments.data.length
}
...
}
commentsCount holds number of comments for active child

Try the following:
{
"data": [
{
"id": "447235535389660_1226199",
"from": {
"name": "Harjeet Walia",
"id": "100004980601083"
},
"message": "Price",
"can_remove": false,
"created_time": "2013-09-06T10:39:01+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "447235535389660_1226152",
"from": {
"name": "Shoba Dhyani Jakhmola",
"id": "100000906896060"
},
"message": "baap re kitna mehnga !",
"can_remove": false,
"created_time": "2013-09-06T10:05:09+0000",
"like_count": 0,
"user_likes": false
}
],
"paging": {
"cursors": {
"after": "MQ==",
"before": "NA=="
}
}
}
then
int commentCount = <JsonNode Var with above data>.path("comments").path("data").size();
Here commentCount will give the number of comments.

Related

Getting Facebook Post all Reactions Count in single Graph API request

As Facebook released the new reaction{NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY} feature for post, but I can not figure out to get all reaction counts in single graph API request.
Has anyone figured out a way to get this detailed reactions per post in single request?
The approach introduced by #CBroe appears to be working using Multiple ID Read Requests.
?ids=7175346442_10153799389241443,7175346442_10153799470326443&fields=reactions.type(LOVE).limit(0).summary(total_count).as(reactions_love),reactions.type(WOW).limit(0).summary(total_count).as(reactions_wow),reactions.type(HAHA).limit(0).summary(total_count).as(reactions_haha),...
Screenshot from Facebook Graph API Explorer:
Once a collection of posts is retrieved, one should be able to read reaction counts grouped by type using a single request. Note, the current limit of ids in the Multiple ID Read Request pattern is 50.
Theoretically possible using Field Expansion in combination with Field Aliases, like this:
?fields=reactions.type(LIKE).limit(0).summary(1).as(like),
reactions.type(WOW).limit(0).summary(1).as(wow),
reactions.type(SAD).limit(0).summary(1).as(sad),…
But there still seem to be some bugs in that regard; I frequently got “An unknown error has occurred” while testing this; f.e. replacing the limit value for LIKE with 1 in the above query triggers it …
Simply use the following as part of your graph query
fbpageid/posts?fields=created_time,story,message,shares,reactions.type(LIKE).limit(0).summary(1).as(like),reactions.type(LOVE).limit(0).summary(1).as(love),reactions.type(HAHA).limit(0).summary(1).as(haha),reactions.type(WOW).limit(0).summary(1).as(wow),reactions.type(SAD).limit(0).summary(1).as(sad),reactions.type(ANGRY).limit(0).summary(1).as(angry)&limit=10
So I'll be getting Post ID, Created time, Story, Message, Share Count, reaction count (currently 6 reaction) using only 1 query. It works with APi v2.9 as well
If you have read_insights permission, you could get reactions in following way for feed or a post
fields=insights.metric(post_reactions_by_type_total).period(lifetime).as(post_reactions_by_type_total)
and you would get results like:
"name": "post_reactions_by_type_total",
"period": "lifetime",
"values": [
{
"value": {
"like": 10,
"love": 2,
"wow": 3,
"haha": 1,
"sorry": 1,
"anger": 2
}
}
],
I found a way to achieve this with 1 request:
GET /{userId}?fields=
posts.as(like){reactions.type(LIKE).limit(0).summary(true)},
posts.as(love){reactions.type(LOVE).limit(0).summary(true)},
posts.as(wow){reactions.type(WOW).limit(0).summary(true)},
posts.as(haha){reactions.type(HAHA).limit(0).summary(true)},
posts.as(sad){reactions.type(SAD).limit(0).summary(true)},
posts.as(angry){reactions.type(ANGRY).limit(0).summary(true)},
posts.as(thankful){reactions.type(THANKFUL).limit(0).summary(true)}
This way you will receive 7 lists of posts (one per each reaction). Example:
{
"like": {
"data": [<list of posts>]
},
"love": {
"data": [<list of posts>]
},
"wow": {
"data": [<list of posts>]
},
"haha": {
"data": [<list of posts>]
},
"sad": {
"data": [<list of posts>]
},
"angry": {
"data": [<list of posts>]
},
"thankful": {
"data": [<list of posts>]
},
"paging": {
"previous": "...",
"next": "..."
},
"id": "<userId>"
}

Facebook Graph API: engagement count breakdown

Using the old API I was able to get on each URL the:
likes,shares,comments,click count. (used the links.getStats?urls=www.google.com)
How do I get all that information via the new API?
I tried using
https://graph.facebook.com/?id=http://www.google.com&fields=og_object{engagement}
From what i understand the engagement count is the sum of all the fields above..
How can i get each one separately? (and in one request!)
I was able to find the Likes and comments count by getting the ID from the URL and then asking for
https://graph.facebook.com/381702034999?fields=likes.limit(0).summary(true),comments.limit(0).summary(true),engagement
But what about shares and clicks? and why the engagement is so much bigger then the sum?
As far as I know it's not possible to reproduce the REST API's results with the current Graph API.
You could make a call like
/?fields=id,share,og_object{engagement{count},likes.summary(true).limit(0),comments.limit(0).summary(true)}&id=http://www.google.com
which only uses ONE request to also get the like and comment counts. It returns
{
"id": "http://www.google.com",
"share": {
"comment_count": 2,
"share_count": 14139003
},
"og_object": {
"engagement": {
"count": 14139003
},
"likes": {
"data": [
],
"summary": {
"total_count": 87227,
"can_like": true,
"has_liked": false
}
},
"comments": {
"data": [
],
"summary": {
"order": "ranked",
"total_count": 1263,
"can_comment": true
}
},
"id": "381702034999"
}
}
Getting the click count is no longer possible IMHO.

Facebook API getting summary of likes in `/links` without deprecated FQL

I'm trying to get the total likes count for posts by a specific user. I'm calling /photos /links and /statuses. When adding ?fields=likes.summary(true) I'm getting back the total sum of likes in /photos and /statuses, but this doesn't work.
How can I get summary of likes (total count) for links posted by a specific user?
I am aware of the option to use FQL, but that is deprecated. (fql?q=SELECT like_info, link_id,comment_info FROM link WHERE link_id IN() )
Use the links edge
me/links?fields=link,likes.summary(true)
The total_count field is the value you want. Although from the documentation
total_count represents the approximate number of nodes on the likes
edge. The actual number of results returned might be different
depending on privacy settings.
Sample data from my feed
{
"link": "http://www.quora.com/permalink/cyGokoKWB",
"id": "XXXXXXXXX",
"created_time": "2015-04-26T02:08:48+0000",
"likes": {
"data": [
{
"id": "XXXXXXXXX",
"name": "XXXXXXXXX"
}
],
"paging": {
"cursors": {
"before": "MTAxNTQ2NTI3OTIxOTA0Mzg=",
"after": "MTAxNTQ2NTI3OTIxOTA0Mzg="
}
},
"summary": {
"total_count": 1
}
}
}
EDIT
#CBroe in the comments has sound advice, for just like's count do a limit(0) so you don't unnecessarily fetch a lot of the likes data and just retrieve the count.
me/links?fields=link,likes.summary(true).limit(0)
Sample data
{
"link": "http://jdh.hamkins.org/transfinite-epistemic-logic-puzzle-challenge/",
"id": "XxXXXXXXXXX",
"created_time": "2015-04-19T04:00:18+0000",
"likes": {
"data": [
],
"summary": {
"total_count": 1
}
}
}

Wrong "Like count" in Facebook Album Stream

we are using the facebook timeline phtot stream, to show the last photos on the website.
We are parsing the url: http://graph.facebook.com/132827113407662/photos
If you have a look at the 5th pic, it shows 25 likes.
If you look at this pic on fb (https://www.facebook.com/photo.php?fbid=635486689808366&set=a.132827113407662.19448.114902408533466&type=1), it shows 31 "Likes".
How can I get the correct number of "likes".
It seems, that the largest number in the stream (http://graph.facebook.com/132827113407662/photos) ist 25. Any like higher than 25 will be ignored in the stream.
Why?
Likes collection is paginated. You can read more about pagination here.
Looks like there is still no way to get all rows count for a collection using graph api request.
But you can get it through FQL.
select like_info, object_id from photo where album_object_id = 132827113407662
Returns:
{
"data": [
...
{
"like_info": {
"can_like": true,
"like_count": 31,
"user_likes": false
},
"object_id": 635486689808366
},
...
]
}
Using the Graph Api you can request fields summary like this: ?fields=likes.limit(1).summary(1)
And the page/album/photo likes are contained in the summary.total_count object.
http://graph.facebook.com/132827113407662/photos?fields=likes.limit(1).summary(1)
This will give you as follows:
{
"data": [
{
"id": "690240794332955",
"created_time": "2013-10-31T18:11:07+0000",
"likes": {
"data": [
{
"id": "100003293421476",
"name": "Rene Geels"
}
],
"paging": {
"cursors": {
"after": "MTAwMDAzMjkzNDIxNDc2",
"before": "MTAwMDAzMjkzNDIxNDc2"
},
"next": "http://graph.facebook.com/690240794332955/likes?summary=1&limit=1&after=MTAwMDAzMjkzNDIxNDc2"
},
"summary": {
"total_count": 78
}
}
}
]
}

could not fetch info from comment table

Facebook just notified me about "July 2013 Breaking Changes". There is one related to my app.
Deprecating 'comments' field from 'stream' FQL table
We are deprecating the 'comments' field from 'stream' FQL table. Please select the 'comment_info' column to fetch the 'can_comment' and 'comment_count' fields (formerly called 'can_post' and 'count'), and use the comment table directly to retrieve the list of comments.
In our app we are using query like this :
SELECT post_id, message, likes.count, comments.count, comments.comment_list FROM stream
WHERE source_id=me() AND actor_id=me() LIMIT 500
and receive response like this :
{
"data": [
{
**"post_id": "100002510712421_451594341600919",**
"message": "text",
"likes": {
"count": 1
},
"comments": {
"count": 2,
"comment_list": [
{
"fromid": 100001228089363,
"time": 1367073822,
"text": "text",
"text_tags": [
],
"id": "100002510712421_451594341600919_1181882",
"likes": 0,
"user_likes": false,
"post_fbid": 452073094886377
},
{
"fromid": 100000020227797,
"time": 1367173047,
"text": "text",
"text_tags": [
],
"id": "100002510712421_451594341600919_1183852",
"likes": 0,
"user_likes": false,
"post_fbid": 452790081481345
}
]
}
},
....
ok now try to fetch info from 'comment' table using given post_id
SELECT id, text, time, fromid FROM comment WHERE
post_id='100002510712421_451594341600919'
{
"data": [
]
}
The response is empty
Can anybody come up with solution? We really need it!
your query looks just fine, are you sure that this post_id exists and you have permission to read it?
SELECT id, text, time, fromid FROM comment WHERE
post_id='125909647492772_502974003098530'
returns
{
"data": [
{
"id": "502974003098530_78616446",
"text": "saugeil!",
"time": 1364309881,
"fromid": 526559276
}
]
}
I'veI run into the same issue.
Surprisingly, I was able to fix it by using only last part of the post_id, i.e.: '451594341600919' instead of '100002510712421_451594341600919'. But it works only sometimes and in your case doesn't work at all.