Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
Created August 15, 2013 02:30
Show Gist options
  • Save rileypaulsen/6237711 to your computer and use it in GitHub Desktop.
Save rileypaulsen/6237711 to your computer and use it in GitHub Desktop.
get the number of Facebook likes, shares, comments, etc. for a given URI
function get_facebook_likes(){
//based on http://halgatewood.com/get-number-of-facebook-likes-for-a-url/
$query = "select total_count,like_count,comment_count,share_count,click_count from link_stat where url='{$uri}'";
$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);
$data = reset(json_decode($output));
//$data->total_count;
//$data->like_count;
//$data->comment_count;
//$data->share_count;
//$data->click_count;
//this should be stored in a Transient/cached to avoid subsequent calls
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment