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?
I don't think Facebook's Open Graph Object i.e. "og_object" provides anything more than comment_count & share_count for a URL. Try this; replace $YOUR_URL with the URL and $ACCESS_TOKEN with your access token in the below link https://graph.facebook.com/v2.5/$YOUR_URL?access_token=$ACCESS_TOKEN
For example:
https://graph.facebook.com/v2.5/http://espn.go.com/nfl/story/_/id/14424066/handing-holiday-gifts-all-32-nfl-teams-nfl?access_token=$ACCESS_TOKEN
Also, if you try to get likes, you would get the following error https://graph.facebook.com/http://rottentomatoes.com?fields=likes&summary=1&access_token=$ACCESS_TOKEN
You need the extended permission "read_stream", then you need to call the Facebook API endpoint, and add
likes,shares
to yourfields
.This call
will return a data array like this
Your question is quite old and Facebook has depreciated FQL now but what you want can still be done using this utility: Facebook Analytics. However you will find that if you want details about who is liking or commenting it will take a long time to get. This is because Facebook only gives a very small chunk of data at a time and a lot of paging is required in order to get everything.
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
For latest 2.1 Graph API, an example to get likes for imdb.com will be
Using this to get the id https://developers.facebook.com/tools/explorer/?method=GET&path=%3Fid%3Dhttp%253A%252F%252Fwww.imdb.com%3Ffields%3Dlikes&version=v2.1
and then get the likes
https://developers.facebook.com/tools/explorer/?method=GET&path=414652589771%2Flikes&version=v2.1
Document
Reference http://harshtechtalk.com/how-get-likes-count-posts-comments-facebook-graph-api/
All previous answers have since been deprecated. This method works as of Aug 2016:
To get the like count of any URL:
GET request: https://graph.facebook.com/[url]/access_token=[access_token]
Then grab shares->share_count from the returned JSON object.
Fan count for a Facebook page:
GET request: https://graph.facebook.com/[url]/?fields=fan_count&access_token=[access_token]
Then grab the 'fan_count' field from the returned JSON object.
You can test this out and get your access token using the Graph API Explorer