Thursday, September 22, 2011

Twitter "Tweet" button does not count tweets? You may be doing it wrong :)

Some time ago, I decided to add the Twitter "Tweet" button to subpages of kalamonsoft.com, so that you could share your feelings about the software I make. The problem was - the button was not counting tweets. Now, it could mean that nobody cares to share their opinion about my products on Twitter, but it was unlikely, as Facebook and Google+ counters did go up.

Searching google did not help at all. I was just about to give up on this button, but I found this Twitter development discussions place, where you could ask questions and hopefully somebody listens. So I asked my question, and lo and behold, @episod answered (praise this guy).

The problem was - in order for the button to work, the HTTP HEAD request has to be properly handled by your site. Now, for most of the self-hosted sites this is not a problem as web servers have this built-in. But I am hosting my site on Google App Engine, and the site is implemented in Python. I am providing handlers to HTTP requests by overriding some methods of the webapp.RequestHandler class. Typically only the get() or post() method is overriden. Which makes HTTP HEAD not work - an error is returned and the twitter button does not like this.

After I added a trivial head() method override, the twitter button immediately started to work. 

So, if you want the twitter button to work on your site, remember to handle HEAD requests properly.

No comments:

Post a Comment