Your Ad Here

Posted By

czachor on 02/16/12


Tagged

google plus


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

AllKnightAccess
bug5


Google Plus Counter


 / Published in: PHP
 

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

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

  1. function get_google_plus1_count($url)
  2. {
  3. $ch = curl_init();
  4. curl_setopt_array($ch, array(
  5. CURLOPT_HTTPHEADER => array('Content-type: application/json'),
  6. CURLOPT_POST => true,
  7. 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"}]',
  8. CURLOPT_RETURNTRANSFER => true,
  9. CURLOPT_SSL_VERIFYPEER => false,
  10. CURLOPT_URL => 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'
  11. ));
  12. $res = curl_exec($ch);
  13. curl_close($ch);
  14.  
  15. if( $res )
  16. {
  17. $json = json_decode($res,true);
  18. return $json[0]['result']['metadata']['globalCounts']['count'];
  19. }
  20. return false;
  21. }

Report this snippet  

You need to login to post a comment.