Archive for August, 2010

Migrating Ruby Twitter apps to OAuth

Saturday, August 14th, 2010

Migrating Twitter API apps from basic authentication to OAuth is up there with hoovering the bathroom and taking out the recycling in the “irritating chores to put off for another day” stakes. However, Twitter’s announcement that they’re dropping basic authentication support at the end of this month has made this task altogether more urgent, like an unexpected visit from the mother-in-law.

If you’re using the Ruby Twitter gem by John Nunemaker, you’ll be happy to learn that it supports OAuth. You’ll be less happy to see that the example code on the homepage merrily omits the difficult part:

# NOT SHOWN: granting access to twitter on website
# and using request token to generate access token

If your Twitter app is of the simple ‘bot’ variety, with a single dedicated account where everything happens, and no need for end users to authenticate against it, then most of the example code and documentation floating around the internet is overkill, sending you down the path of sessions and callback URLs, when all you really want to know is: what do I put in the ‘register an application’ form? How do I get hold of these tokens? And what do I do with this PIN code it’s just given me?

I eventually found a blog post at BeefyApps which cleared things up immensely, and so I’ve now reshuffled their code snippet into a mini command line utility which will spit out those all-important tokens and tell you how to use them.

twitter_oauth_setup.rb on gist.github.com