I'm using the Facebook API to get the like/share count for given URLs. The strange thing is that it seems to be quite inconsistent in returning results. For example, this page returns results:
https://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url='http://www.groupon.com/deals/seattlehelitourscom-by-classic-helicopter-corp'&format=json
Whereas, this one does not:
https://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url='http://www.livingsocial.com/deals/278194-sunset-kayaking-hot-chowder'&format=json
The second page clearly has a share count on it, and when I inspect the HTML of the page, the URL which is being used to share is the one I've placed into the API request above. However, the API does not respond with any count information for either number of likes or shares.
Any clues on why the API might be responding for some URLs but not for others?
Facebook Graph is awesome. Just do something like below. I've entereted perl.org URL, you can put any URL there.
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://perl.org%27
For graph API v2.1, you can get the like count using 1 call only and, therefore, no need to go through the paging.
For example, to get the number of likes of http://www.imdb.com
https://graph.facebook.com/414652589771/likes?summary=1
Graph API Explorer https://developers.facebook.com/tools/explorer/?method=GET&path=414652589771%2Flikes%3Fsummary%3D1&version=v2.1
It is somehow not documented (at least at the moment I submit this answer...). I found the answer in https://stackoverflow.com/a/18198957/1822624
use below URL and replace myurl with your post url and you will get all the things
http://api.facebook.com/restserver.php?method=links.getStats&urls=myurl
but keep in mind it will give you response in XML format only
Example :
As of August 8th, 2016, FQLs are deprecated.
Update 10/2017 (v2.10):
Here's a non-deprecated way to get a given URL's like and share count (no access token required):
Result:
JQuery Example:
Reference:
https://developers.facebook.com/docs/graph-api/reference/url
Use the open graph API. Here is a live example querying how many likes "Coca Cola" has.
https://developers.facebook.com/tools/explorer/?method=GET&path=cocacola%3Ffields%3Dlikes
Which boils down to:
https://graph.facebook.com/cocacola?fields=likes
Which you could do in an AJAX GET
The result is:
I see this nice tutorial on how to get the like count from facebook using PHP.
here is a sample code.. I don't know how to paste the code with correct format in here, so just kindly visit this link for better view of the code.
Creating a Custom Facebook like Counter