How To Get The Google+ Share Count For a URL

  • follow us in feedly
Published September 25, 2013 by Brad Knutson
Google+ Share Count

I recently built Share Tally, a social sharing tracking tool. I crawled the internet and determined how to gather share data for many social networks including Facebook, Twitter, Linkedin, and Pinterest.

Each of the major social network makes social sharing data available to us through unofficial APIs. This isn’t exactly an ideal solution, but it’s the same method that the typical social sharing buttons with counters use to show their sharing data.

Google, of course, had to make things more difficult. The Google+ +1 button doesn’t use APIs to get its data, the button is generated directly from Google’s index. In order to get the number that appears in the share button, we have to use a little PHP.

Getting the Google +1 Count


	function get_plusones($url) {
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "");
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, '&#91;{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}&#93;');
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
		$curl_results = curl_exec ($curl);
		curl_close ($curl);
		$json = json_decode($curl_results, true);
		return intval( $json&#91;0&#93;&#91;'result'&#93;&#91;'metadata'&#93;&#91;'globalCounts'&#93;&#91;'count'&#93; );
	$plusone = get_plusones($url);
	echo $plusone;

OK, that seems like a lot of work, doesn’t it? Nevertheless, we have our number of +1s for our given $url, which we’ll need to specify in our script.

That’s all well and good, but how do we determine the Google+ Share count? The +1 button doesn’t give us this data, so we have to look at other methods.

Getting the Google+ Share Count

As you may be aware, there isn’t a Google+ Share button that has a counter. In fact, the official Google+ Share button does include a counter, but the count is the exact same number as the +1 button, so this isn’t a reliable number of “shares.”

I had given up counting Google+ Shares when I found AJ Kohn’s Google Ripples Bookmarketlet. AJ’s method used Javascript to open a new tab with the Google Ripples page for the URL.

Google+ Ripples

It’s a great tool, and I found that I could use this same method server side to return the number of public shares for a given URL.


	$shares_url = ''. $url;
	$response = file_get_contents( $shares_url );
	$shares_match = preg_match('@(&#91;0-9&#93;+) public shares@',$response,$matches);	
	$shares = $matches&#91;1&#93;;
	echo $shares;

Essentially all I’m doing is generating the same URL that AJ’s bookmarklet and getting the HTML that it generates. I’m then using the built-in PHP function preg_match() to find the number of shares.

It’s really not that complicated is it?

Note: Take this example at face value. It’s an unofficial method, and there are no guarantees it will work tomorrow. Don’t think of this as an absolute solution, think of it as a short term fix that will be updated as we go.

This method is nothing special, but I couldn’t find anything else like this on the internet, so enjoy!

The following two tabs change content below.
Founder at Inbounderish
Brad Knutson is a Web Developer in the Twin Cities area of Minnesota. He has experience working with WordPress and Drupal, and also has an interest in SEO and Inbound Marketing.

Keep Up-to-Date



See a complete list of topics discussed in blog posts here.

Check These Out

Get 2 Weeks Free! Sign Up Today! Premium Managed WordPress Hosting Genesis Framework for WordPress SEO is complex. Tools should be simple. Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

12 thoughts on “How To Get The Google+ Share Count For a URL

    1. Brad Knutson Post author

      Hello Tushar,

      The official Google+ share button is a count of +1s, thanks for asking! The share count I was looking for was a sum of all public shares and reshares, and the Ripples page gives us that data.

  1. Ben Racicot

    Hey BRad,
    Very creative! Seems like all last years tricks to get the G+ count are failing in this Feb 2014. I’M getting this PHP error with that code:
    Warning: file_get_contents(): Unable to find the wrapper "https" – did you forget to enable it when you configured PHP? in C:\wamp\www\domainsales\wp-content\themes\domain-theme\home.php on line 212
    Call Stack…
    ( ! ) Warning: file_get_contents( failed to open stream: Result too large in C:\wamp\www\…

    Anyone else?

    1. Brad Knutson Post author

      Hmm…seems like a PHP error specific to your hosting environment. I’m not able to duplicate it. The file path to home.php also suggests you’re doing this through WordPress?

  2. randy

    It’s now Feb 2014 and I’m messing around with this now. no matter what i do i cannot get past the “Access Not Configured. Please use Google Developers Console to activate the API for your project.” error message. I’ve looked through the dashboard and enabled all 3 Google+ APIs. Perhaps I’ve not got the other settings right, I suspect my IP address but I’m quite sure it is correct.

    The other thing I don’t quite grok is the “”method”:”pos.plusones.get”” bit of data. I’m not seeing “pos.plusones.get” in any API docs so far. I do see other kinds of permission-strings but that one is elusive.

    Google’s got a lot going for it, these are amazing services, but their documentation is like roadkill.

    1. Brad Knutson Post author

      For this example, I am not tapping into the official Google+ API in any way, it’s all unofficial and requires no authentication.

    1. Brad Knutson Post author

      Ivan – thanks for sharing, however this post is about getting the Google+ Share count, your method returns the +1 count, just like all the other services.

  3. Henry Wright

    When I visit the URL in my browser, I can see my page has been shared. Yet, when I echo the share count to screen, it remains the same (doesn’t increment each time the page is shared). Could this be due to some sort of caching going on? It’s only been a few hours since I shared the page.


Share Your Thoughts

Your email address will not be shown.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">