Now that the Google +1 button is out the Social SEO battle will inevitably be stepped up a gear. We know the search engines are using social shares and likes to impact the rankings, and Google’s +1 button is their way of ensuring at least some of this data is directly in their hands.
So obviously, tracking this data is very important for SEOs, and both Facebook and Twitter have APIs for pulling in Likes and Tweets, but currently we are left without a public API for doing this with Google’s +1 button. With a little digging behind the scenes I managed to find the API they use for the button. So now us SEOs can use it to pull out the Google +1 counts for lists of URLs (if you are interested in the technical details then see the optional section below).
I’ve put together a public Google Spreadsheet which can do all of this automatically for you – you just need to enter a list of URLs and the spreadsheet will pull in the counts for you. To get started, open the spreadsheet (download it right here) and select “Make a copy” from the File menu (you’ll need to be logged into a Google account to do this). Enter the URLs in the the A column (ensuring you pay attention to trailing slashed and they include http:// at the start), and the counts will appear in column B. You should see something like this:
Technical Bits
If you want to write your own solution, you can rip the code from the spreadsheet. The URL for the service is:
https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ
It is a JSON-RPC setup, meaning you send a JSON formatted request and get a JSON formatted response. The request should be via POST in the following format:
-
[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"http://www.test.com","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]
The request will be returned like so:
-
[{"result": { "kind": "pos#plusones", "id": "http://www.google.com/", "isSetByViewer": false, "metadata": {"type": "URL", "globalCounts": {"count": 3097.0} } } "id": "p"}]
Example PHP Code
If you want to implement this server side, here is some example PHP code to get you going:
-
-
<?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'];
-
-
?>
There is an interactive demo here: Google +1 Button API demo.
Wrap Up
If you want to track social shares and likes and aren’t already setup with a Google Doc for the Twitter/Facebook parts you can head over to this post on Distilled which will help you get going. Combined with the above and you can build a complete system for tracking social search signals. Have fun!
Great post! Thanks.
It’s certainly a start 🙂
Thanks! This is just what I was looking for. I wish Google would make it as easy as Facebook and Twitter to get the count.
I agree! I’m sure they will in time, but not sure why they haven’t from the get go. This private API isn’t quite as straightforward as the Twitter and FB ones, but works perfectly for the moment. Fingers crossed they release a public API with proper support.
Would love to hear what you use it for. 🙂
Hi Tom, I was wondering if you have any suggestions as to how I can integrate the google plus 1 button into my wordpress site ?
When I copy your exact code(except change the API key to mine), I get a error returned from Google. Any idea what the problem could be? It’s returning a 400 error.
Error:
[ { “error”: { “code”: 400, “message”: “Bad Request”, “data”: [ { “domain”: “global”, “reason”: “badRequest”, “message”: “Bad Request” } ] }, “id”: “p” } ]
Hi Jake,
You’ve answered your own question! Don’t change the key – it is a developerKey that is the same for everyone. Changing it will give you a 400 error. Let me know how you get on (and what you are using it for – I love to know about applications!). 🙂
-Tom
Cctv installers – I recommend this plugin: Google +1 WP Plugin from Pleer. It works great. 🙂
Thanks for the help, seems I was getting ahead of myself changing the API key without being told to ;P.
On another note, you wouldn’t happen to know how to get the amount of stumbles for a URL would you? They provide no public API and I’m struggling to find any code pasted online.
Ruby one-liner 😀
require ‘curb’
require ‘json’
JSON.parse((Curl::Easy.http_post(‘https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ’,[{‘method’=>’pos.plusones.get’,’id’=>’p’,’params’=>{‘nolog’=>true,’id’=>’!->URL’widget’,’userId’=>’@viewer’,’groupId’=>’@self’},’jsonrpc’=>’2.0′,’key’=>’p’,’apiVersion’=>’v1′}]){|curl|curl.headers[‘Accept’]=’application/json’;curl.headers[‘Content-Type’]=’application/json’;curl.headers[‘Api-Version’]=’2.2′}).body_str)[‘result’][‘metadata’][‘globalCounts’][‘count’]
Sorry, parser killed my code
require ‘curb’
require ‘json’
JSON.parse((Curl::Easy.http_post(‘https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ’,[{‘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|curl.headers[‘Accept’]=’application/json’;curl.headers[‘Content-Type’]=’application/json’;curl.headers[‘Api-Version’]=’2.2′}).body_str)[‘result’][‘metadata’][‘globalCounts’][‘count’]
On another note, I just found this class on CodeCanyon. Looks useful for those of us that need to count multiple statistics. SocialCounter Class
Thanks to share it dude, nice!
PHP: I would add
CURLOPT_SSL_VERIFYPEER = false
, usecurl_setopt_array
for performance reasons and put the whole thing in a function like this: /php-google-plus-one-count-apiBut the best version is async processing of multiple urls at once.
Thanks a lot for the code – I’ve been monitorig the web for such a solution for a couple of weeks already, but found this post only today. And I was wondering – how do you find out what kind of request is made in such cases? I’ve seen people similarly ripping apart Twitter private API for tweet count, but I never got to know how it is done. Could you share the approach?
Thanks, this is working wonderfully.
I am passing following JSON to URL you mentioned. I am getting error below json string. Same code was working five days back. What can be the reason behind the error
JSON String I am passing to googleplusone
[{“method”:”pos.plusones.get”,”id”:”p”,”params”:{“nolog”:true,”id”:”http://yahoo.com”,”source”:”widget”,”userId”:”@viewer”,”groupId”:”@self”},”jsonrpc”:”2.0″,”key”:”p”,”apiVersion”:”v1″}]
Error I am getting :
{“error”:{“code”:-32700,”message”:”A JSONObject text must begin with ‘{‘ at character 0 of “,”data”:[{“domain”:”global”,”reason”:”parseError”,”message”:”A JSONObject text must begin with ‘{‘ at character 0 of “}]}}
The big difference of Google +1 to other social media is it will have influence on the search results people see at Google.
I think it doesn’t work … Maybe … Google has change anything ?
My curl_getinfo:
Array ( [url] => https://clients6.google.com/rpc [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0.112 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0 )
May be the problem is the ssl certificate ?
Great tutorial. I had a little trouble at first, and kept getting the “Bad Request” error.
I discovered the reason I was getting it is because I was leaving off a trailing slash on a domain, i.e., I had put “http://example.com”, instead of “http://example.com/”. If anyone else is having similar problems, you might want to check that.
Works great, but I did notice a quirk in the spreadsheet – it won’t update automatically on refresh. I have to copy/paste the urls into new cells – then the count updates.
The spreadsheet works great, thanks for that. I do have a problem with the PHP code though. It does not return the same values as the spreadsheet but lower +1 counts. Anybody that has noticed this, or even better, found a workaround?
Thanks!
Hi,
this was useful information. I have small problem. When I put $url = ($_GET[‘url’]); and wish to check +1 counts this don’t work. Anybody know how to fix that?
Thank you.
You must post it (not GET) to the JSON-RPC service. You can find another full PHP implementation on:
http://olegnax.com/927-counter-goole-plusone-twitter-facebook-buttons/
I’ve no idea why Google doesn’t yet have an API like Facebook or Twitter to make this easy but thanks to you we can still get the count easily. Works perfectly and does exactly what I wanted.
Thanks.
Hi, I have one question. I want followers of my brand page. Means who has added me to their circles. It seems g+ is showing pluses and followers total at top. I am not sure how can i get that. You examples fetches pluses count for a website. I want such as Facebook or Twitter like fans or followers count. Is it possible?
OK, I’m not sure if I am the only one attempting this via javascript or not, but I seem to be the only commenter with this problem:
XMLHttpRequest cannot load https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ. Origin http://mydomain.com is not allowed by Access-Control-Allow-Origin.
Any chance this is something stupid I am missing, or do I need to be doing this server-side? I cannot imagine their server would be interpreting the requesting domain any differently from the server versus the client. Any ideas?
Hi Scott,
Browsers generally won’t allow you to do cross-site requests with Javascript for security reasons… 🙁
Hi Scott, try with JSONP.
I’m also trying this with jquery and ajax but isn’t working. I have opened a question on Stackoverflow http://stackoverflow.com/questions/8929177/getting-counts-for-twitter-links-facebook-likes-and-google-1-with-jquery-and-a
Cheers
Where you able to resolved the google+ issue?
Where you able to resolve the google+ issue?
Hi, I’m not familiar with php. Is there a way directly retrieval the count using an url? Could we put the parameters in the url? I tried several times but couldn’t get it right. If you can show me how to do it, it will be great!
Thanks
curious
Or how to do that using curl?
I tried
curl -v -k -H “Content-Type: application/json” -X POST -d ‘{“method”:”pos.plusones.get”,”id”:”p”,”params”:{“nolog”:true,”id”:”http://www.test.com”,”source”:”widget”,”userId”:”@viewer”,”groupId”:”@self”},”jsonrpc”:”2.0″,”key”:”p”,”apiVersion”:”v1″}’ https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ
but it didn’t work. I got an “error code 400…”
Could you please help me?
Very helpful article indeed. I have to admit that I always follow all blog posts about plus one, so it was quite interesting to read this. Thank you
Hi All…
I’ve tried several times an keep getting a 400 error. I haven’t changed the API code either
Array
(
[0] => Array
(
[error] => Array
(
[code] => 400
[message] => Invalid Value
[data] => Array
(
[0] => Array
(
[domain] => global
[reason] => invalid
[message] => Invalid Value
)
)
)
[id] => p
)
)
Any ideas? Has Google gone live with this and or killed this key?
Thanks.
I am also getting same error
I’m getting same error too
It will give above error if url does not have the Google+ button.
I’m getting same error too
this doesn’t work no more!
it is absurd that we can’t get the count
how will we write this tag (defined by google’s schema.org)
<meta name="interactionCount" content="UserPlusOnes:NUMBER_THAT_I_CANT_GET" >
if we can’t get the count? it is non-sense!
The main disadvantage of this is that you can check G+ count for only one specified page/URL, not for entire website. Thats sad, but actually there’s no way to count +1 for entire website 🙁 If you want to quick check of +1 and Like count of page, try http://www.seoptimer.com for this.
Wow This post and comments are really helpful. Thanks a lot.
Yeah, this is great to read the article. Many thanks, Tom Anthony
Hey, When I try to use this method, on a wordpress website I got this error :
‘ Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\wordpress\framework\wp-content\themes\framework\lib\functions-extanded.php on line 435 ‘
Any idea? Or how to make so it is defined?
Hi, great post! thanks. I have a question about this. Is it possible get the globalCounts for a Google+ Page? for example: https://plus.google.com/+FCBarcelona/ .. a lot of thanks.
ufff.. I found the solution. you must make the request with the identifier. For exemple:
$url = “https://plus.google.com/116151548242653888082”;
Yea! it works.
Spreadsheet gives me error: Unknown function name GETPLUSONES
Hey, I have the same problem, unknow function getplusones… Did U manage to find a solution?
cheers,
Lucas
How did u get the google plus counts? I dint get ….could you please share the code for getPlusones() ?
What about share button count? (not +1’s). can we count them?
an example with javascript please I can not even get it ..
Hi Tom! I really enjoy your post. This small webservice is very useful for me to quickly find G+ count for single page or small bunch of URLs. It would be (drastically) more useful to know if I could use it (or maybe there is another way) to grab g+ count for a bigger number… let’s say for 50K URLs daily basis.
I can also divide it to the smaller number but I can’t find if there is any query limit.
is can’t work,all is error message : Access Not Configured. Please use Google Developers Console to activate the API for your project. but i was active g+ services.
and i can’t find about this api about “pos.plusones.get” explanation
how to get my own API key?