Facebook Graph API: Check if user has liked a specific post - facebook

I am rather new to Facebook Graph API and I'm trying to find out if a user has liked a specific post.
Right now, in order to achieve this, I get all the likes for that post and then I iterate through them to find a match. But this procedure requires a lot of requests when the number of likes is too high, as the maximum number of likes per request appears to be 100.
Is there any better way to check if the user has liked the post?

Request the summary of the likes (post_id?fields=likes.limit(0).summary(1)), then you will get a data structure that looks like this:
{
"likes": {
"data": [
],
"summary": {
"total_count": 1,
"can_like": true,
"has_liked": false
}
},
"id": "…"
}
The properties can_like and has_liked reflect the values for the user who’s access token you used to make the request.
UPDATE
The latest version of Graph API today is v2.8. In this version you can get the reactions also. It is better to use reactions than likes as reactions also includes the Love, WOW and HAHA etc reactions which likes does not.
You can add the field for reactions's summary instead of likes's summary as below
fields=reactions.limit(0).summary(true)
Using this you will get the reactions summary as below
"reactions": {
"data": [
],
"summary": {
"total_count": 6,
"viewer_reaction": "LOVE"
}
}, ......
Notice the "viewer_reaction": "LOVE" which means you have given a reaction to the post which is LOVE. It's value could be any one of LIKE, LOVE, HAHA, WOW, SAD, ANGRY, NONE. The NONE means you have not liked the post.

Related

How to get likes count from facebook graph api which is shared from my web app?

I am able to get share count and comments count but unable to get the likes count.
https://graph.facebook.com/?ids=MY_URL this API gives the response as,
{
"MY_URL": {
"share": {
"comment_count": 0,
"share_count": 13,
},
"id": "MY_URL",
}
}
In the same way, I just need to get likes count/ reaction count from API. Please help. Thanks in Advance
Check out the engagement field - https://developers.facebook.com/docs/graph-api/reference/v3.2/url
It returns four different counters - comment_count, comment_plugin_count, reaction_count and share_count.
The reaction_count would be the number of all reactions (like, love, sad, …) - that is as much “detail” as you can get in this regard for external Open Graph objects.
Example in Graph API Explorer, for the object http://example.com/:
https://developers.facebook.com/tools/explorer?method=GET&path=%3Fids%3Dhttp%253A%252F%252Fexample.com%252F%26fields%3Dengagement&version=v3.2

Get Facebook share/like/comment count of URL

Prior to today, I used the following URL to get the Facebook share/like/comment count of a URL:
https://api.facebook.com/method/links.getStats?format=json&urls=http://stackoverflow.com/
Today, Facebook removed this feature. So now I'm using this:
https://graph.facebook.com/v2.7?emc=rss&fields=og_object{engagement},share&access_token=<ACCESS_TOKEN_GOES_HERE>&id=http://stackoverflow.com/
Which outputs:
{
"og_object": {
"engagement": {
"count": 45267,
"social_sentence": "45K people like this."
},
"id": "10150180465825637"
},
"share": {
"comment_count": 12,
"share_count": 45267
},
"id": "http://stackoverflow.com/"
}
The problem is, share_count is the total of likes + comments + shares (as far as I know).
Is there a way to get the number of likes, comments, and shares separately?
Looks like a bug in fb-api.
My solution:
receive the number of shares/comments as you describe in your question with
graph.facebook.com/?fields=og_object{id},share&id=https://stackoverflow.com/
save shares/comments count
save fb object-id of url
og_object->id
get likes count with (max limit is 1000, then you can use paging):
graph.facebook.com/OBJECT_ID/likes?access_token=ACCESS_TOKEN&pretty=1&limit=1000
UPD 2016-08-22
I found a solution that allows you to get the number of likes/reposts/comments in one step:
https://graph.facebook.com/?fields=og_object{likes.limit(0).summary(true)},share&ids=http://google.com,http://twitter.com
It is not currently possible.
Facebook is adding likes/shares/comments for URLs and returning them as shared_count.
Not possible to return correct number of individual likes/shares/comments, and that is not clear in the Graph API documentation. Not clear if it is a bug or a documentation error.
The old Rest API that provided this data was turned off on the 18th August.
There is a comment from a Facebook engineer explaining this in reply to a bug report, in the answer to this Stack Overflow question:
Getting Facebook Share, Like and Comment Counts for a Given URL with API Graph v2.6
You can also subscribe to this bug report at Facebook, but is a bit old with still no solution:
https://developers.facebook.com/bugs/748651458568287/

How to get people who have shared specific FB post?

It's easy to get people who have liked post: https://graph.facebook.com/19292868552_10150189643478553/likes
How can I get people who have shared this post ?
Using the Graph Explorer with a post that has shares:
https://graph.facebook.com/20531316728_10151733211311729?fields=shares
The output is:
{
"shares": {
"count": 1806
},
"id": "20531316728_10151733211311729",
"created_time": "2013-02-10T12:59:25+0000"
}
Of course if you remove the fields parameter you see all the fields associated with that object.
EDIT: The post on Facebook - https://www.facebook.com/photo.php?fbid=10151733211231729&set=a.376995711728.190761.20531316728&type=1

Facebook Likes for multiple pages in a domain

The problem to solve:
Imagine I have a domain and corresponding web site at http://my-awesome-site
On this site I have 10,000 pages.
Each page has a Facebook Like button.
How do I retrieve the number of likes per page from the Facebook Graph?
It's possible to look up the total number of likes per URL using a simple GET request (examples: google.com, google.com/reader, news.google.com). But is it possible to get a similar list for an entire domain, broken down by page? Something with results like:
{
"id": "http://my-awesome-site/",
"shares": 12345
},
{
"id": "http://my-awesome-site/page1.html",
"shares": 5678
},
....
{
"id": "http://my-awesome-site/page10000.html",
"shares": 9012
}
You can do this also via facebook graph
seperate ids with commas
https://graph.facebook.com/?ids=http://techcrunch.com,http://mashable.com
the result will be a json, shown below
{
"http://mashable.com": {
"id": "http://mashable.com",
"shares": 14436
},
"http://techcrunch.com": {
"id": "http://techcrunch.com",
"shares": 2144
}
}
I think that the best you can do is (using the link_stat table):
SELECT url, share_count
FROM link_stat
WHERE url IN ("http://my-awesome-site/", "http://my-awesome-site/page1.html"...)
But if you have 10,000 pages you'll have to break it into multiple requests.
You can however use the Batch Requests api to then combine some requests.
That solution should lower the amount of http requests considerably if that is what you're after.

Accessing all replies to a comment with Graph API

I'm having trouble accessing all replies from a Facebook post using the Graph API. (A reply is a post made in response to another comment).
For example, going to
https://graph.facebook.com/comments/?ids=http://developers.facebook.com/blog/post/472
yields comments in JSON form. While this JSON document caps the number of commments at 25, one can simply access the remaining comments using the 'paging' and 'next' keys.
Replies, however, appear to be limited to 10 per comment. Take for instance this snippet of JSON from https://graph.facebook.com/comments/?ids=http://developers.facebook.com/blog/post/472
{
"id": "10150090402026572_14446101", ... ,
"message": "Excited for the launch of Comments Box this morning!",
"created_time": "2011-03-01T17:06:45+0000",
"comments": {
"data": [...]
"count": 74
},
The "comments" : "data" array holds the replies to a comment. The "count" variable below that indicates how many replies there are.
Is there any way to access all replies on a comment?
Any help would be much appreciated. Thank you.
If you add:
&limit=100
to the end of the url: https://graph.facebook.com/comments/?ids=http://developers.facebook.com/blog/post/472
It will display 100 comments, just change the 100 to whatever the count is to display all comments.