Querying Facebook Like Count and Public Page Properties

There are various way to query the Like count of Facebook pages.

If you just want to want the live stats of a given Facebook page, Quintly provides a live statistics page. Upon entering the FB page name (www.facebook.com/[page-name] becomeswww.quintly.com/facebook-live-statistics/[page-name]), the page displays a live chart updating every couple of seconds.

But you can also query Facebook directly using the FQL API or the Graph API.

Here’s a sample URL for the FQL API

https://api.facebook.com/method/fql.query?query=select
  %20url,share_count,like_count,comment_count,total_count
  %20from%20link_stat
  %20where%20url=%27[my-fb-url]%27

(enter this into the navigation bar. [my-fb-url] is the complete URL starting with “https://

The result is an XML document in the form

<fql_query_response list="true">
  <link_stat>
    <url>https://www.facebook.com/[page-name]</url>
    <share_count>[value]</share_count>
    <like_count>[value]</like_count>
    <comment_count>[value]</comment_count>
    <total_count>[value]</total_count>
  </link_stat>
</fql_query_response>

and like_count or total_count will be the values you are looking for.

The Graph has a simpler approach, using simply

http://graph.facebook.com/?id=https://www.facebook.com/%5Bpage-name%5D

Here the result is given as JSON value, and the relevant JSON property is “likes”:

{
   "id": "74865038590",
..."likes": 194804,
...
}

If you want to query repeatedly, here’s a simple PowerShell solution using FQL:

$wc = New-Object system.Net.WebClient;
$response = $wc.downloadString("https://api.facebook.com/method/fql.query?query=
    select%20%20url,share_count,like_count,comment_count,total_count
    %20from%20link_stat%20where%20url=%27https://www.facebook.com/[page-name]%27")
$xml = [xml] $response
$xml.fql_query_response.link_stat

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: