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

      • I’ve created my own key but it always gives me a “Access Not Configured” error message when I call the API. I have enabled the Google+ API in the API console.

        The only way I’ve seen this work is by using the AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ key (who’s key is that?), r by not using a key. However, not using a key will get you throttled/blocked after you use it too many times.

        Do you have any idea of how I can use my own key?

Webmentions

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

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

  • Open Site Explorer gets a makeover | Urban Influence October 1, 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 October 1, 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 October 1, 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 October 1, 2014

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

  • Social SEO Share Counts Private & Public APIs October 1, 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 October 1, 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 […]