Wrong likes number via Facebook Graph API - facebook-graph-api

There is couple ways to get number of page likes in graph api, and the most simple way is just get JSON response via this url, for instance:
http://graph.facebook.com/?id=http://cnn.com/
However, that method returns wrong number of likes:
{
"id": "http://cnn.com/",
"shares": 138855,
"comments": 39
}
CNN page has facebook widget that shows actual number of likes (1.4 million):
http://i.imgur.com/IQlaq.png
Is there a way to get likes number from API exactly the same as in facebook like widget on the page?

Your view of what these numbers are talking about is wrong:
The number 1.4 million corresponds the number of people who liked the page CNN International.
The query http://graph.facebook.com/?id=http://cnn.com/ looks for the number of times the Open Graph object at cnn.com has been shared.
Is there a way to get likes number from API exactly the same as in
facebook like widget on the page?
There's always a possiblity of lag. If you want absolute real-time you should implement a javascript event listener on the edge.create and track it yourself. Personally, I don't need things in definite real-time, so I prefer using FQL with the link_stat table.

Related

Subscribe to facebook graph api webhook for website likes count change

I have a website with some posts that have facebook like buttons. I would like to be able to sort those posts based on fb like count.
I can get number of likes for any post querying https://graph.facebook.com/?ids=ABSOLUTE_URL_TO_POST but I would like to be able to subscribe to Graph Api, so endpoint of my server can get notified whenever someones likes any of those posts.
That way I could store number of likes in my DB and then be able to sort posts based on that.
However, I am not able to find any suitable event in FB Graph API that I could subscribe to.
Any ideas? Thanks!
As correctly pointed out by luschn, there is no webhook api for getting likes count. Also if you will try get this likes count by polling graph.facebook.com you will quickly hit limit of allowed requests by facebook.
There is no way how to do this at the moment.

Facebook Graph API get likes/reactions

I'm trying to fetch some data from page posts on Facebook with the Graph API. I'm using Python normally but I try the queries first with the Exploration tool offered by Facebook.
I used the page_id + post_id to get the number of reactions (I would also like to get the count for each different reaction) and likes. But it just returns nothing. I get the data for the shares though. I have the post open on another tab and it has likes and reactions.
Don't know what I'm doing wrong.

Any Method to Get number of LIKES of a URL or PAGE of Facebook?

i am trying to show number of likes on my website of my page but i dont want that facebook widget. Please help me - Any API Request that i can use to pull number of likes.
Thanks in advance
Yes, you can do this easily with Facebook Graph API.
There are two options:
if you want to get number of likes of some Page or URL, use this piece of code:
https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27http://www.facebook.com/facebook/%27&format=json
NOTE that you need to change the part where i wrote URL that's http://www.facebook.com/facebook
The New Graph API provides a minimal pull request code e.g.
http://graph.facebook.com/[Type your Page USERNAME here]?fields=likes
Here replace [Type your page username] part with username e.g.
http://graph.facebook.com/facebook?fields=likes`
and it will give you an output like:
{
"id": "20531316728",
"likes": 92990262
}
I hope this helps and fulfills your purpose.

Facebook Connect: get total number of photos

The title is self explanatory. I know you can do a request to
/me/photos
with arguments for the limit and the offset, but is there any quick way of finding out the total number of photos? I want to pick a random selection of photos and I do not want to have to download all 500+ photos worth of metadata to the client to shuffle. The facebook API documentation has not offered me any joy.
Why dont you get the albums instead? http://developers.facebook.com/docs/reference/api/album/
each album has a count property that says how many pictures it has.

Get Facebook "Like" count for every page on my domain

I have integrated the Facebook "Like" button into a lot of pages in my site. I want to display the most "Liked" pages on my site in a list, but I can't figure out how to get that data from Facebook in one request. So far, I have been able to get the "Like" count for individual pages using the following FQL query:
SELECT share_count, like_count, comment_count, total_count
FROM link_stat
WHERE url="http://www.mysite.com/some-page"
However, getting the count for each page on my site one at a time is not really feasible. Aside from having a large number of pages, new pages are being created constantly (new user profiles, new blogs and blog articles, etc), which would make getting complete statistics for my site a complicated process and would involve calling Facebook's API thousands of times.
Is there a way to get a count of how many times each page on my domain has been "Liked" in one request? Or just the top 10 most "Liked" pages, or something similar?
Actually I would do it this way:
$arrayOfPages = array('url1', 'url2', 'url3');
$listOfPages = implode(',', $arrayOfPages);
SELECT share_count, like_count, comment_count, total_count, url
FROM link_stat
WHERE url IN ($listOfPages)
That would give you all the data with the URL as a unique identifier without having to break Facebook's policy against fake users. You can dynamically create the $arrayOfPages variable from a query on your site's database.
In continuation to Salil's answer, here are the some of the major APIs sharedcount.com are using (full list here: http://sharedcount.com/documentation.php)
You can use sharedcount's API to get a general summary, or write something yourself using the APIs:
Facebook: http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls=%%URL%%&format=json
Twitter: http://urls.api.twitter.com/1/urls/count.json?url=%%URL%%&callback=twttr.receiveCount
Google +1 +1 counts are retrieved via a JSON-RPC POST call that requires an API key (To get a google API key - https://developers.google.com/+/api/oauth#apikey):
POST URL:
https://clients6.google.com/rpc?key=%%API-KEY%%
POST Body:
[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"%%URL%%","source":"widget","userId":"#viewer","groupId":"#self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]
It will be difficult to get FB likes for all your pages in one query, but you can get individual share count for every page of your site. Apart from the share count you can also get the breakup of numbers for individual social network for which your site page is shared. Insert you domain name at http://sharedcount.com/?url=http%3A%2F%2Fwww.parasitech.net%2F with appropriate suggestions provided to you. You can get numbers for Facebook, Twitter, Google+, Diggs, Linkedin, Google Buzz, Delicious and StumbleUpon.
Apparently there's no 'LIKE' in FQL. Which was my first suggestion..
Though you can use the "IN" operator, like so:
SELECT share_count, like_count, comment_count, total_count
FROM link_stat
WHERE "http://www.mysite.com/" IN url
ORDER BY like_count
LIMIT 10;
1) create a fake user on fb which will likes only pages from your domain or some other way to save your urls in fb with possibility to get them by FQL later
2) query:
SELECT share_count, like_count, comment_count, total_count
FROM link_stat WHERE url in (SELECT object_id FROM like WHERE user_id="fake_user_id")
3) don`t forget about decrement on 1 each like count ;), sort and show
Maybe you can just query the number of likes for each page each time the page is viewed. This won't be precise, but keeping in mind that the most popular pages will be viewed more often it might be good enough.
Additionally, you can use a batch process to query the number of likes of all the page or at least the top N last created ones every couple of hours. Most of the time you won't get the correct result, but in most cases your users don't need the correct result but a good enough approximation.
If you just need the count from every page, Super Social Media Tracker could provide that.
http://apps.microsoft.com/windows/en-US/app/super-social-media-tracker/a56c8971-42e2-4eb4-9b05-7e52233b4e1e
But it's slow for massive pages.
After some looking around, we may be better off using FQL with graph API:
http://graph.facebook.com/fql?q=select%20comment_count%2C%20share_count%2C%20like_count%20from%20link_stat%20where%20url%20%3D%20%22http%3A%2F%2Fmashable.com%2F2013%2F01%2F30%2Ffacebook-twitter-blackberry-10%2F%22
Results are
{
"data": [
{
"comment_count": 3,
"share_count": 91,
"like_count": 5
}
]
}