Facebook Graph API: engagement count breakdown - facebook

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.

Related

FB Graph API - Tried accessing nonexisting field (reactions) on node type (Photo)

I am working with FB Graph API to get the names of the users who like or react to my post. By using
get/version/{post-id}/likes
I have been able to get the names and IDs of all likers. Now I also want to get other reactions i.e. HAHA or Love reactions, but when I use get/version/{post-id}/reactions I get this error
{
"error": {
"message": "(#100) Tried accessing nonexisting field (reactions) on node type (Photo)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Abwl9IBIxglskXT3yivpWUm"
}
}
Is it possible to get all reactions or not?
The users will authorize the app so that's not a problem.
So basically after 3 days of wait, I got no answer. So I decided to post an answer myself. What I found in these 3 days is that it is not possible to get all the reactions. Likes and Care are the only data you will get.
If I ever found a way to get it all, I will update the answer.
It is possible to get all the reactions on a post (including Photos) by requesting this endpoint:
{user_id}_{post_id}?fields=
reactions.type(LOVE).limit(0).summary(total_count).as(love),
reactions.type(WOW).limit(0).summary(total_count).as(wow),
reactions.type(HAHA).limit(0).summary(total_count).as(haha),
reactions.type(LIKE).limit(0).summary(total_count).as(like),
reactions.type(ANGRY).limit(0).summary(total_count).as(angry),
reactions.type(SAD).limit(0).summary(total_count).as(sad)
(Remove all newlines, I put them in only to make the URL more readable).
This returns
{
"love": {
"data": [
],
"summary": {
"total_count": 50
}
},
"wow": {
"data": [
],
"summary": {
"total_count": 20
}
},
"haha": {
"data": [
],
"summary": {
"total_count": 24
}
},
"like": {
"data": [
],
"summary": {
"total_count": 60
}
},
"angry": {
"data": [
],
"summary": {
"total_count": 1
}
},
"sad": {
"data": [
],
"summary": {
"total_count": 1
}
},
"id": "{user_id}_{post_id}"
}
I got this answer from this post.
It seems that the Facebook API does not support getting reactions on Photos using the shorthand id, but it supports getting reactions using the longhand id, which is {user_id}_{post_id}.

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 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
}
}
}
]
}

Facebook graph api comment count

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.