Counting the number of mentions for a hashtag
A Google+ user was interested in getting a count of the number of mentions for a particular hashtag on Google+. Seeing as the Activities API and Search should be able to enable this functionality easily, I wrote a web application that retrieves a set of posts for a particular time period and then graphs them using the Google charts API. You can see the Google+ tag tracker demo on wheresgus.com.
The following screenshot shows the UI and a search that I performed last night while the vice presidential debate was going on.
The app is really simple right now and has a few known issues, most notably, it will lock up your browser because I’m performing synchronous requests to the Google+ API. In code, I’m doing this:
var request = new XMLHttpRequest(); request.open('GET', URL, false);
when I need to do this:
var request = new XMLHttpRequest(); request.open('GET', URL, true);
That third parameter, when set to false, forces the call to finish before returning control to the browser. You would think that I just need to set that parameter to false and am good to go, but it’s much more complicated than that. If the calls are performing asynchronously, all of the requests would occur “simultaneously” which means that I would not know which part of the requests I would be on – a race condition.
Anyways, I will try to fix it and afterwards will write a follow up blog post with more information on the story of how it works. I also have a long todo list of features that I would expect to be in such a tool like:
- Customization of date ranges
- Alternative strategies to grabbing posts chronologically
- Caching requests to make it faster
- Giving more options on the chart styling
Since it’s a demo, I probably won’t do much more after fixing the synchronous call, but I’ll probably open source the sample code at some point soon and you’re welcome to use/reuse/fix it at any time if you see fit to do it.