Skip to content

Instantly share code, notes, and snippets.

@cmwinters
Last active March 7, 2016 09:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmwinters/cc867a5be41707953d23 to your computer and use it in GitHub Desktop.
Save cmwinters/cc867a5be41707953d23 to your computer and use it in GitHub Desktop.
Get a raw Google+ share count in Rails

Google+ Share Count

While there's no officially documented method in the Google+ API way to get a raw share count, there are some tricks you can do to acheive this.

For this example, we're working in a Rails app with Nokogiri. We'll use Nokogiri to open the Google+ fastbutton tool and return the share count.

require 'open-uri'
require 'nokogiri'

@url = "http://yoursite.com"

googleplus_data = Nokogiri::HTML(open("https://plusone.google.com/_/+1/fastbutton?url=#{@url}"))
self.gplus_count = googleplus_data.css('div#aggregateCount')[0].text.to_i
@fer-ri
Copy link

fer-ri commented Mar 7, 2016

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment