Return to Snippet

Revision: 55652
at February 16, 2012 00:50 by czachor


Updated Code
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;
}

Revision: 55651
at February 16, 2012 00:29 by czachor


Initial Code
$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":"' . $url . '","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'));
 
        $curl_results = curl_exec ($ch);
        curl_close ($ch);
 
        $parsed_results = json_decode($curl_results, true);
 
        echo $parsed_results[0]['result']['metadata']['globalCounts']['count'];

Initial URL
http://lucido-media.de/blog/php-google-plus-one-count-api

Initial Description
interesting app: http://codecanyon.net/item/socialcounter-php-class-social-statistics/282826

Initial Title
Google Plus Counter

Initial Tags
google

Initial Language
PHP