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

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

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

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.

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.

Facebook Graph API - Get like count on page/group photos

I've been testing graph API and ran into a problem. How can I get like count from photos of a page/group?
I'm administrator/creator of a group. When entering in https://developers.facebook.com/tools/explorer/ certain photo ID from that group it brings almost all data, even comments, but not the like count. For like part it needs (according to docs) access token despite the fact that anyone can access that info.
How to get access token of my page/group with required permissions and how to use it to get info I need?
If possible I would like to get JSON from a single address if it is possible.
This is possible with a page (even without an access token!) and here's how:
Visit the page on the graph
Get the page's id by going to the page's url:
https://www.facebook.com/pages/platform/19292868552
The number on the end of the URL is the page's id. Take that id and use it with the graph explorer (here) or just visit it directly.
Visit the page's albums
Now appending albums to that url will give you all the albums the page has, including wall photos:
https://graph.facebook.com/19292868552/albums
The output looks like this:
{
"data": [
{
"id": "10150160810478553",
"from": {
"name": "Facebook Platform",
"category": "Product/service",
"id": "19292868552"
},
"name": "Bringing Operation Developer Love to Europe",
"description": "Blog post: http://developers.facebook.com/blog/post/479\n\nVideos and presentations uploaded here: http://developers.facebook.com/videos/",
"location": "Berlin, Paris, London",
"link": "https://www.facebook.com/album.php?fbid=10150160810478553&id=19292868552&aid=285301",
"cover_photo": "10150160811078553",
"count": 32,
"type": "normal",
"created_time": "2011-04-06T23:05:44+0000",
"updated_time": "2011-04-06T23:33:20+0000",
"comments": {
..... etc ....
Selecting an album
For each object in the data array there is an id and a name. Using these two fields you can select the album that contains the photos you want. The first album in this result is "Bringing Operation Developer Love to Europe". Lets look at this albums photos.
Seeing Photos
If you've followed the answer up to this point the next step should be fairly obvious. Use the id for the album you want and append photos to the graph url:
https://graph.facebook.com/10150160810478553/photos
Seeing a Photo's likes
Much like selecting an album, simply use an id in the output of the above step and append likes to the url to see a photos likes:
https://graph.facebook.com/10150160813853553/likes
Output:
{
"data": [
{
"id": "1163036945",
"name": "Aditya Pn"
},
{
"id": "1555885347",
"name": "Nadin M\u00f6ller"
},
{
"id": "100001643068103",
"name": "Umut Ayg\u00fcn"
},
{
"id": "100000165334510",
"name": "Alessandra Milfont"
},
{
"id": "100001472353494",
"name": "Sayer Mohammad Naz"
},
{
"id": "1051008973",
"name": "Jenson Daniel Chambi"
},
{
"id": "100000233515895",
"name": "Ruby Atiga"
},
Using this output you can simply count the number of entries in the data array to get the like count.
Note that all of this is possible from using the graph explorer by clicking on ids in the output box and the connections sidebar (except for the last /likes connection, which will hopefully be added soon. I hope this helps. Also, you do not need an access token to do any of this because pages are public. Hope this helps!
You can get the comments/likes count without having to paginate through all likes 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
}
}
}
/me/feed returns a LIKES field
I used a solution where I simply find the number of items in the array which display LIKES
Object.keys(item.likes.data).length
This returns the "length" of an object -- which is equal to the number of likes.
http://graph.facebook.com/223766074374957
there is a likes property in the response
{
"name": "Bejeweled Blitz",
"is_published": true,
"website": "https://apps.facebook.com/bejeweledblitz/",
"username": "bejeweledblitz",
"products": "Bejeweled Blitz\nBejeweled\nPlants vs. Zombies\nPeggle\nZuma\nChuzzle\nBookworm Adventures\n \nFor a complete list, please visit www.popcap.com\n ",
"about": "We're the award-winning hit, Bejeweled Blitz! The lightning-fast puzzle game where you have just 60-seconds to match as many gems as you can! Start Blitzing now!",
"general_info": "Speed is the name of the game in Bejeweled Blitz! Bejeweled Blitz is a speedier take on the classic Bejeweled match-3 gem game mechanic. Your goal is to make as many matches as you can in 60-seconds to really make your score soar! But you won't be going it alone! There are special ways to enhance your Bejeweled Blitz game - like Boosts (power-ups like Scrambler, which moves all the gems around the board or +5 seconds, to add 5 seconds more gem-matching time!) and the popular, Rare Gems. Rare Gems are like extra-special power-ups that can REALLY take your game to the next level!",
"talking_about_count": 22487,
"category": "App page",
"id": "223766074374957",
"link": "https://www.facebook.com/bejeweledblitz",
"likes": 5796324,
"cover": {
"cover_id": 383412771743619,
"source": "http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash4/s720x720/417018_383412771743619_1056862875_n.jpg",
"offset_y": 0
}
}