Created
August 15, 2013 02:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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