Facebook API can be used in PHP to measure the popularity of any website or webpage in Facebook. Specifically, to get the number of likes, comments, shares and clicks received by any website in Facebook. Do it with this simple PHP code, by replacing the URL address in bold letters:
$query = "select total_count,like_count,comment_count,share_count,click_count from
link_stat where url='www.thesartorialist.com'";
$call = "https://api.facebook.com/method/fql.query?query=" .
rawurlencode($query) . "&format=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$stats = json_decode($output);
var_dump($stats);
Then, depending on the metric you'd like to extract, use one of these codes:
Add this PHP code to retrieve the number of likes of any website in Facebook:
$likes = $stats->like_count;
echo $likes;
Add this PHP code to retrieve the number of comments of any website in Facebook:
$comments = $stats->comment_count;
echo $comments;
Add this PHP code to retrieve the number of shares of any website in Facebook:
$shares = $stats->share_count;
echo $shares;
Add this PHP code to retrieve the number of clicks of any website in Facebook:
$clicks = $stats->click_count;
echo $clicks;