— words and things

number of plus ones for any url

The Google+ Platform developers have done a great job with their API and documentation so far. Unfortunately at an API level they have not yet implemented the ability to grab the number of plus ones for any given URL. Not having time to wait for the issue that is currently pending within the google-plus-platform issues tracker, I decided to take a deeper dive into the source of the plus one button’s underlying javascript. Another unminified adventure into Google’s mysterious ways of mastering the interwebs.

During the train ride from Hamburg to Berlin this past Friday I was doing some thinking on how exactly to extract the count of plus one’s of any given url. I knew that the API would not support my request and that was about it. I spent a few hours examining the button’s source code to tried and figure out exactly what kind of voodoo they were doing to let you magically embed the button.

Typical of most “embedable widgets” like this, is an init script.  Google gives to you their version of this init script within the “Getting Started” section for the +1 Button ( plusone.js ). This script sets some globals ( among other things ) and then embed’s the main script. In this particular case, the script that is being embedded is doing a lot of different things that I did not take the time to fully understand because I quickly found the main thing I was looking for. The point at which the browser creates the URL of the iframe that contains the actual button html. Once I found that it was easy for me to use jsdom and jquery to scrape the src of the iframe that is embedded by the main script.

When crawling minified javascript manually you want to look for key words. In this particular case the text “src” and “iframe” were what led me to exact code I was looking for. Another big help in figuring out complex minified code is using break points in Chrome’s Dev Tools as well as the window.console.trace() method.

Feel free to clone the simple utility I created to help me gain access to the number of plus ones for a given url. I will post more detail of the project I am building this script for in the future. The inline comments should be enough to help you get started.

Submit comment