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
}
}
}
]
}
Related
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}.
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.
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
}
}
}
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.
How do I get the 'like' count of a post on Facebook?
I got a link graph.facebook.com/userid_postid that says says I can do this. But How do I find the user or page ID and the ID of the post?
For example, if take any post on the fan page:
http://www.facebook.com/TipsLearnings of site http://adityabajaj.com
If I make a post on the fan page above, and people like the post, how would I get the number of likes of that post? I want to have that number available to show on a separate website.
You can use FQL
SELECT like_info.like_count, share_info.share_count, comment_info.comment_count FROM stream WHERE post_id = 'your_post_id'
You can get a list of most recent posts a fan page made by using /<PAGE_ID>/posts (which you can find for your page by navigating to http://graph.facebook.com/myown.easytipsandtricks, or just use the username) with a valid access token. From that, you get an object that looks like this:
"data": [
{
"id": "22092443056_115909438544849",
"from": {
"name": "Starbucks",
"category": "Food/beverages",
"id": "22092443056"
},
// ...
"shares": {
"count": 708
},
"likes": {
"data": [
{
"name": "Shanna Gonzales",
"id": "100000244536406"
}
],
"count": 17129
},
"comments": {
"count": 759
}
}
// ... and more posts
Accessing the count subfield of each of those fields should tell you shares, likes and comments, respectively.
You can get the comments/likes count without having to paginate by using the fields parameter in combination with likes.limit(1).summary(true). For example, a search api query for pizza below will give you all public posts and their likes count summarized:
https://graph.facebook.com/search?q=pizza&type=post&fields=id,name,likes.limit(1).summary(true)
results (truncated):
{
"data": [
{
"id": "47883936273_659693910762305",
"name": "Instagram",
"created_time": "2014-02-16T01:15:29+0000",
"likes": {
"data": [
{
"id": "100002243084532",
"name": "Yvette Martin"
}
],
"paging": {
"cursors": {
"after": "MTAwMDAyMjQzMDg0NTMy",
"before": "MTAwMDAyMjQzMDg0NTMy"
},
"next": "https://graph.facebook.com/47883936273_659693910762305/likes?limit=1&summary=1&after=MTAwMDAyMjQzMDg0NTMy"
},
"summary": {
"total_count": 13682
}
}
},
{
"id": "136336876521150_314001148754721",
"name": "Pizza Box Turns into Plates & Storage Unit!",
"created_time": "2014-02-15T21:20:00+0000",
"likes": {
"data": [
{
"id": "100005373008864",
"name": "Liliana Campoli"
}
],
"paging": {
"cursors": {
"after": "MTAwMDA1MzczMDA4ODY0",
"before": "MTAwMDA1MzczMDA4ODY0"
},
"next": "https://graph.facebook.com/136336876521150_314001148754721/likes?limit=1&summary=1&after=MTAwMDA1MzczMDA4ODY0"
},
"summary": {
"total_count": 2792
}
}
}