The Code
Below is a super simple function that retrieves a JSON feed of comments, likes and shares for any URL you provide.
function facebook_shares($url){
$fql = “SELECT url, normalized_url, share_count, like_count, comment_count, “;
$fql .= “total_count, commentsbox_count, comments_fbid, click_count FROM “;
$fql .= “link_stat WHERE url = ‘”.$url.”‘”;
$apifql=”https://api.facebook.com/method/fql.query?format=json&query=”.urlencode($fql);
$fb_json=file_get_contents($apifql);
return json_decode($fb_json);
}
How to use
$fb = facebook_shares(‘https://www.facebook.com/redbull’);
// facebook share count
echo $fb[0]->share_count;
// facebook like count
echo $fb[0]->like_count;
// facebook comment count
echo $fb[0]->comment_count;