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?
Check the Original Post Select your name on the main Facebook page. Scroll down to look at your posts. If you see text directly underneath a post that says something like '1 share' (or more if you're popular), that means it's been shared. Select the text to gain more information about who has shared it.
UPDATE: This solution is no longer valid. FQLs are deprecated since August 7th, 2016.
https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22http://www.techlila.com%22
Also http://api.facebook.com/restserver.php?method=links.getStats&urls=http://www.techlila.com will show you all the data like 'Share Count', 'Like Count' and 'Comment Count' and total of all these.
Change the URL (i.e. http://www.techlila.com) as per your need.
This is the correct URL, I'm getting right results.
EDIT (May 2017): as of v2.9 you can make a graph API call where ID is the URL and select the 'engagement' field, below is a link with the example from the graph explorer.
https://developers.facebook.com/tools/explorer/?method=GET&path=%3Fid%3Dhttp%3A%2F%2Fcomunidade.edp.pt%26fields%3Dengagement&version=v2.9
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):
https://graph.facebook.com/?fields=og_object{likes.summary(total_count).limit(0)},share&id=https://www.stackoverflow.com
Result:
{ "og_object": { "likes": { "data": [ ], "summary": { "total_count": 83 } }, "id": "10151023731873397" }, "share": { "comment_count": 0, "share_count": 2915 }, "id": "https://www.stackoverflow.com" }
JQuery Example:
$.get('https://graph.facebook.com/' + '?fields=og_object{likes.summary(total_count).limit(0)},share&id=' + url-goes-here, function (data) { if (data) { var like_count = data.og_object.likes.summary.total_count; var share_count = data.share.share_count; } });
Reference:
https://developers.facebook.com/docs/graph-api/reference/url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With