One of the latest and very helpful social button is the Google Plus Button. It is very helpful because it affects the SEO points of the website in Google Algorithm since its owned by the Google Company.
Here’s one great tutorial that gets the Google Plus Button Count Using PHP and CURL. You need to enable your curl on your server to make the codes work. To do that, you need to update your php.ini file then try to search and uncomment this line.
;extension=php_curl.dll
When you have already set your CURL on your server, you can try to do this. Here is the sample code for the Google Plus Button Count.
$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_SSL_VERIFYPEER, false);
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'));
$result = curl_exec ($ch);
curl_close ($ch);
The code above gets the count of the Google Plus Buttons of a specific url. We can use a JSON Decode function to get the data from the API Site.
Lets make a PHP Function that will do all the process above. Check this out.
PHP CODE:
//Get count of g+ of URL
function gplus_shares($url){
// G+ DATA
$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_SSL_VERIFYPEER, false);
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'));
$result = curl_exec ($ch);
curl_close ($ch);
$json = json_decode($result, true);
return intval($json[0]['result']['metadata']['globalCounts']['count']);
}
Now we have a function, we can use it as much as we can. Here’s the sample code on how we can echo the number of count.
HOW TO VIEW IT:
//GPlus count $gplus_shares = gplus_shares($url); echo $gplus_shares;
Sparky! We can now get the Google Plus Count of the URL Using a PHP Function, Curl, and JSON. Help and let others know this tutorial and Share the knowledge.
Incoming search terms:
- get follower count google plus php
- get g count with jquery
- google count jquery
- PHP function json_decode and cUrl enabled on your server
wilbert Santos
He is the founder and the man behind Upgraded Tutorials that focuses on creative and helpful web development tutorials. He is a Web Developer and knows CodeIgniter, WordPress and other frameworks. He loves web development and creating cool stuff. Add him on Facebook and Google
- Web |
- Google+ |
- More Posts (11)






