Get Facebook share/like/comment count of URL - facebook

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/

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

Facebook Places API incomplete & incorrect response

My app is having issues with getting facebook page data: "rating_count" & "overall_star_rating". The issue have been found about 20 hours ago, between 2 am UTC to 6 am UTC 12th of October, so probably it's on Facebook side.
For example, request to all graph versions older 2.8 would same response:
https://graph.facebook.com/v2.8/pageID?fields=overall_star_rating,rating_count&access_token=YourToken
{
"overall_star_rating": 0,
"rating_count": 0,
"id": "pageID"
}
Look at zero counts - blank for all the pages. It doesn't matter what token you're using - app/user/page one, response is the same.
Requesting newer API versions (v2.10 & v2.9) give similar, but worth (incomplete) response:
{
"rating_count": 0,
"id": "pageID"
}
Both counts, "overall_star_rating" & "rating_count" are valid according to documentation.
Did anyone experience the issue? How did you fix it?
BTW, if you request "ratings" along with counts, but you'll have to use Page Access Token for that, you'll get an array of reviews of the page, but zero stats. I'm thinking of counting reviews & calculating rating based on them, but this way is wrong for many reasons.

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

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.

How to get the Facebook Share count for a given URL?

Given a particular URL, how can I get the Facebook Share count for it?
There is one way to get the count, i know that platforms like sharedcount.com are using this:
https://api.facebook.com/method/links.getStats?urls={your-url}/&format=json
I highly suggest not using FQL anymore, it is deprecated and no longer available in v2.1+ of the Graph API: https://developers.facebook.com/docs/apps/changelog#v2_1_deprecations
Edit: This is deprecated, but there is another possibility: Get FB likes, shares and comments for a URL using PHP - with no limit
The easiest way to do this is to fire off a request to the Graph API.
The following query will select:
like_count
total_count
share_count
click_count
comment_count
https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27http://imdb.com%27
{
"data": [
{
"like_count": 62024,
"total_count": 191031,
"share_count": 93544,
"click_count": 71308,
"comment_count": 35463
}
]
}
Just replace the google.com with whatever URL you want to get the information for.

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.