Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created July 1, 2011 08:48
Show Gist options
  • Save bueltge/1058115 to your computer and use it in GitHub Desktop.
Save bueltge/1058115 to your computer and use it in GitHub Desktop.
Google+ Button "Likes" auslesen
function get_google_plus1_count($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.$url.'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'
));
$res = curl_exec($ch);
curl_close($ch);
if( $res )
{
$json = json_decode($res,true);
return $json[0]['result']['metadata']['globalCounts']['count'];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment