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>"
}
Related
I'm trying to get all comments from Facebook Comments Plugin running in my application.
Here's a step by step of what i have done
https://graph.facebook.com/{myUrl}
{
"share": {
"comment_count": 43,
"share_count": 1695
},
"og_object": {
"id": {myObjectID},
"description": {myDescription},
"title": {myTitle},
"type": "website",
"updated_time": "2018-05-28T21:50:37+0000"
},
"id": {myUrl}
}
https://graph.facebook.com/{myObjectID}/comments?access_token={pageToken}
{
"data": [ ],
"paging": {
"cursors": {
"before": {beforePointer},
"after": {afterPointer}
},
"next": {nextUrl}
}
}
So despite comment_count = 43, data field is empty.
It's also weird that a {nextUrl} is given although not showing any results.
Haven't found nothing about this in the recent update due to GDPR.
Any ideas?
The graph API has changed recently due to privacy and GDPR concerns.
To get all comments for a page or user first you need to make a call to get all your posts and then make a call for each post to get comments.
Please view the following example end to get all the posts and then post_ids (the call is similar for user posts).
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
post_id looks something like this - 5704324444475_570454233326 and is in the id field of each returned post.
Then call the get comments endpoint from the graph API using the ID(s) returned by the first endpoint.
https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
You'll need to make a separate call for each posts to get that post's comments.
Since the REST API has gone, I need to find another way to read the likes for pages of our webapp.
According to the Graph API docs, the following should return the likes for any object (such as a page):
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true
Oops, An access token is required to request this resource. Turns out, instead of a real token, you can also build an ad-hoc token witht the app ID and secret:
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true&access_token={ID}|{SECRET}
The above returns a JSON payload, however, it's empty even though I'm trying this with a page having almost 200 likes:
{
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
Maybe a permissions problem? The app domain and the page URL domain are identical.
Big thanks for any hints to solve this riddle!
It does work with a simple App Access Token too, but i assume you get the wrong idea about that endpoint. There is no way to get the "Page Fans", you can only get "other Pages the current Page likes" with it. Just try this with your App Access Token:
https://graph.facebook.com/bladauhu/likes?access_token=APPID|APPSECRET
It should return the following JSON:
{
"data": [
{
"name": "FKK Scibes Skulls",
"id": "1391253501090151"
},
{
"name": "Dodgeball Austria",
"id": "387249994631552"
},
{
"name": "Turbojugend Scibes",
"id": "105248832848054"
},
{
"name": "HYDRA! Das endgute Satiremagazin.",
"id": "167084486537"
},
{
"name": "VLÜ Hydra",
"id": "113680962002559"
}
],
"paging": {
"cursors": {
"before": "MTM5MTI1MzUwMTA5MDE1MQZDZD",
"after": "MTEzNjgwOTYyMDAyNTU5"
}
}
}
More information about Tokens:
http://www.devils-heaven.com/facebook-access-tokens/
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://developers.facebook.com/docs/apps/changelog#v2_6_changes:
The likes field on the Page node has been renamed to fan_count
As luschn said in their answer, likes are the other pages liked by that page; if you want to get the number of people that like the page itself, you need to request fan_count.
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 figure out how to access the guest list data of an event on Facebook and the example given in the Facebook documentation located at https://developers.facebook.com/docs/reference/api/event/ is:
https://graph.facebook.com/331218348435/invited
However, when I test this in the explorer I get:
{
"error": "Request failed"
}
Am I missing something?
The endpoint is most definitely not deprecated.
The problem here is that there are simply too many people invited to that event! There are too many results to return in a single query...
If you specify a limit you will get the results you need:
https://graph.facebook.com/331218348435/invited?limit=10
The response for that request would be something like this :
{
"data": [
{
"name": "xxx",
"rsvp_status": "attending",
"id": "111"
},
{
"name": "yyy",
"rsvp_status": "attending",
"id": "222"
},
... (8 more results) ...
],
"paging": {
"next": "https://graph.facebook.com/331218348435/invited?limit=10&offset=10&__after_id=29606639"
}
}
Note that there is a paging result returned as well - this is the URL you will need to query in order to get the next batch of results. It uses the limit parameter and also the offset parameter to ensure that you don't get duplicate results.
In my example, I've given a limit of 10 users per response, but I've managed to get data even when specifying 1000 results. The bigger the limit you provide the longer the request will take to return data.
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.