I have been searching all over the internet on how to get programaticaly google plus one button count. Finally i found this article Here is the Php Script mentioned in the arcticle.
<?php
$url = "http://www.tomanthony.co.uk/";
$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'];
?>
I tried everything,i have been sitting on it for 3 hours but could get it to work. But it seems to work for him perfectly fine.It is perfectly straight forward and simple script.
I even used firebug to examine the requests.I tried substituting the post data value with one i found .
[{"method":"pos.plusones.get","id":"pos.plusones.get","params":{"cdx":"cb4","id":"http://www.tomanthony.co.uk/google_plus_one_api_example.php","source":"widget","container":"http://www.tomanthony.co.uk/google_plus_one_api_example.php","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"pos.plusones.get","apiVersion":"v1"}]
I dont have a clue where am i going wrong.Its just a simple code.
var_dump($curl_results)
to see what's coming back? – Damnvar_dump($curl_results)
I gotboolean false
– Gieseckeecho curl_error($ch)
after calling curl_exec to retrieve the error message. In general, NEVER assume a call to an external service succeeded, as you are. Always check for error conditions. Network glitches happen far too often to NOT check for them. – Damnecho curl_error($ch)
and i got thisSSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
– Gieseckecurl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
Got it solved by adding above lines.Thank You very much. :) – Giesecke