in All Posts, APIs/Mashups, SEO/SEM

Google +1 Button SEO – Getting Bulk Counts with the hidden API

Pile of +1 Buttons 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:

Google Spreadsheet showing Google +1 Counts

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:

  1. [{"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:

  1. [{"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:

  1.  
  2. <?php
  3.  
  4.  $url = "http://www.tomanthony.co.uk/";
  5.  
  6.  $ch = curl_init();  
  7.  curl_setopt($ch, CURLOPT_URL, "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ");
  8.  curl_setopt($ch, CURLOPT_POST, 1);
  9.  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"}]');
  10.  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  11.  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  12.  
  13.    
  14.  $curl_results = curl_exec ($ch);
  15.  curl_close ($ch);
  16.  
  17.  $parsed_results = json_decode($curl_results, true);
  18.  
  19.  echo $parsed_results[0]['result']['metadata']['globalCounts']['count'];
  20.  
  21. ?>

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!

Write a Comment

Comment

57 Comments

  1. 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. 🙂

  2. 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” } ]

  3. 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

  4. 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.

  5. 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’]

  6. 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’]

  7. 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?

  8. 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 “}]}}

  9. The big difference of Google +1 to other social media is it will have influence on the search results people see at Google.

  10. 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 ?

  11. 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.

  12. 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!

  13. 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.

  14. 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?

  15. 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?

  16. 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?

  17. 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.

  18. 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!

  19. 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.

  20. 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?

  21. 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.

  22. 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

Webmentions

  • How do I get the counter of a google plus +1 button? – Code D3 July 9, 2014

    […] tried this link:1 , but this is not very […]

  • Open Site Explorer gets a makeover | Urban Influence July 9, 2014

    […] +1’s API (if you can call it that) is undocumented, but a nicely-timed blog article by Tom Anthony solved that […]

  • Retrieving Google Plus share count with wp_remote_post - Wordpress Helpdesk July 9, 2014

    […] found a working technique using barebones CURL ( http://www.tomanthony.co.uk/blog/google_plus_one_button_seo_count_api/comment-page-1/ ). But previously, I've tried hard to get it to work with WordPress' functions like wp_remote_post […]

  • Accessing Google +1 stats via Google Analytics API? | StackAnswer.com July 9, 2014

    […] found this blog post about accessing Google +1 stats. However, we are rolling out a fairly large project that needs to […]

  • [PHP]or[java script]google+1のカウント数だけを取得して表示する | CreativeLife July 9, 2014

    […] Google +1 Button SEO – Getting Bulk Counts with the hidden API – Tom Anthony […]

  • Social SEO Share Counts Private & Public APIs July 9, 2014

    […] from Google’s hidden API in their Google Plus widget, find the details at Tom’s blog: www.tomanthony.co.uk/blog/google_plus_one_button_seo_count_api/ […]

  • Is there a way to count how many "Likes", "Tweets", "+1's", etc., a given URL has? - Quora July 9, 2014

    […] and PeopleAddFind Questions, Topics or PeopleCancelFlag Answer1 Comment • 3:08pm on Thursdayhttp://www.tomanthony.co.uk/blog… for Google+Jonathan Ong • 4:34pmView 1 Comment Edit Link Text Show answer summary preview […]