|
<?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']; |
|
} |
|
|
|
?> |