Facebook Likes for multiple pages in a domain - facebook

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.

Related

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/

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.

How to query facebook with FQL to get usernames who liked and commented on a post or a photo

Ok what i want to do is simple but i am not sure it can be done or not
Here my post and image that i want to query
Original share image :
https://www.facebook.com/MonsterMMORPG/photos/a.551985868170404.1073741825.198765706825757/694573437244979/?type=1
The reshare of the image
https://www.facebook.com/MonsterMMORPG/posts/699889243380065
Now i want to get people who liked image and post and also commented on them
I am trying to get userids of who liked via FQL like below but it returns nothing
SELECT user_id FROM like WHERE post_id=699889243380065
I am doing this at graph api explorer panel here screenshot
first image works second fails
You can use Facebook-graph-api to get your list of likes, as follows:
https://graph.facebook.com/v2.0/699889243380065/likes
(with valid tokens of course)
You'll receive the following list:
{
"data": [
{
"id": "xxx",
"name": "xxx"
},
{
"id": "xxx",
"name": "xxx"
},
etc
To get list of comments via graph-api:
https://graph.facebook.com/v2.0/699889243380065/comments

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