If you have a site hosting the Facebook Like button you may at times want to query Facebook for the number of Likes displayed within the button. Here’s how.
I couldn’t find a way to do it with Facebook’s Graph API, but there’s good support for it in the FQL API. You can craft up queries by hand, as shown below, and issue them right from your web browser. The response is an XML document with the statistics for the URLs you want to know about. There are also FQL wrapper libraries in several languages… for Ruby I had some success with the fb_graph gem.
Multiple URLs example:
https://api.facebook.com/method/fql.query?query=select url,like_count, total_count, share_count, click_count from link_stat where url in(“http://bing.com”, “http://google.com”, “http://facebook.com”, “http://twitter.com”)
Single URL example:
Within the XML results, the “total_count” attribute is the number shown within the Facebook Like widget.