Revisions
-
kopiro revised this gist
Oct 29, 2011 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ <?php /* Return object of shared counts */ function get_social_count( $link ) { $r = (object)array(); $r->facebook = get_social_count_facebook($link); @@ -8,21 +9,25 @@ function get_social_count( $link ) { return $r; } /* Return shared counts */ function get_social_count_facebook( $link ) { $link = urlencode($link); $data = file_get_contents("http://graph.facebook.com/?id=$link"); $json = json_decode($data, true); $count = $json["shares"]; return $count ? $count : 0; } /* Return retweet counts */ function get_social_count_twitter( $link ) { $link = urlencode($link); $data = file_get_contents("http://urls.api.twitter.com/1/urls/count.json?url={$link}"); $json = json_decode($data, true); $count = $json["count"]; return $count ? $count : 0; } /* Return shared counts */ function get_social_count_gplus( $link ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ"); @@ -33,7 +38,8 @@ function get_social_count_gplus( $link ) { $data = curl_exec ($ch); curl_close ($ch); $json = json_decode($data, true); $count = $json[0]['result']['metadata']['globalCounts']['count']; return $count ? $count : 0; } ?> -
kopiro created this gist
Oct 29, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ <?php function get_social_count( $link ) { $r = (object)array(); $r->facebook = get_social_count_facebook($link); $r->twitter = get_social_count_twitter($link); $r->gplus = get_social_count_gplus($link); return $r; } function get_social_count_facebook( $link ) { $link = urlencode($link); $query = urlencode("SELECT like_count FROM link_stat WHERE url = '$link'"); $data = file_get_contents("https://graph.facebook.com/fql?q=$query"); $json = json_decode($data, true); return $json["data"][0]["like_count"]; } function get_social_count_twitter( $link ) { $link = urlencode($link); $data = file_get_contents("http://urls.api.twitter.com/1/urls/count.json?url={$link}"); $json = json_decode($data, true); return $json["count"]; } function get_social_count_gplus( $link ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.$link.'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); $data = curl_exec ($ch); curl_close ($ch); $json = json_decode($data, true); return $json[0]['result']['metadata']['globalCounts']['count']; } ?>