In a previous post, I explained how to use an FQL query to get the current number of “likes” for a page, even if that page is age-gated. This time we’re going to look at the FQL query to do something similar for external pages (content pages not on Facebook, like blog posts, etc.)
For this demo, I’ll use the url of my primary site, Snipe.Net, with a url of http://www.snipe.net.[php]require_once ‘facebook-php-sdk/src/facebook.php’;
// Create our Application instance.
$facebook = new Facebook(array(
‘appId’ => ‘YOUR APP ID’,
‘secret’ => ‘XXXXXXXXXXXXXXXXXXXXXXXXXX’,
‘cookie’ => true,
// run the FQL query for the content page
$external_result = $facebook->api(array(
‘method’ => ‘fql.query’,
‘query’ => ‘SELECT share_count, like_count, comment_count, total_count FROM link_stat WHERE url=”http://www.snipe.net”;’
The “Like” is a Lie
Something to bear in mind here – we’re querying for a few different numbers. The “like” number you see on the like widgets all over the internet is not the actual number of likes – it’s a combination of likes, shares and comment counts.
To demonstrate this, let’s look at the output of that FQL query. If we add:[php]print_r($external_result);[/php]
 => Array
[share_count] => 18
[like_count] => 6
[comment_count] => 9
[total_count] => 33
My like button says 33, but the actual like count is 6. But 18+6+9 = 33. So what you see on the like button is actually the
total_count, not a true number of likes.
From here, you can use those numbers directly as numbers, or you can display them as a string using
number_format() to add commas (like 1,000,000).