Last time I described how to integrate a Rails app with Facebook Connect, today I’d like to take a moment and give you a small tour on how to integrate it with Twitter OAuth.
In case you missed it, OAuth is a protocol for authorizing APIs without the need of supplying any passwords in our application – we just store the tokens we later use for interacting with the API. Ok, let’s get started.
One thing you’ll need is a Rails App – I’ll be using my usual Twitter-clone app called Statusr. I’d like the statuses from Statusr to be pushed to Twitter.
The first thing I’ll need is to register my application on Twitter. To do that, log in to Twitter and go to http://twitter.com/oauth_clients/new. Fill out the form and remember to specify the callback url - it should be the action that will handle the callback from Twitter. It must be a valid url, so http://localhost or http://localhost:3000 will not work. You need to set up a domain name on your machine to make it work (on Mac OS X you can use NetInfo). In my case it’s http://statusr.local/twitter/new. You can always change it later if you’re not sure now.
The Application Type should be set to Browser. Also, select Read & Write under Default Access type. I will not be covering logging with Twitter now, so leave that option empty. When you’re done, click save.
Congratulations, you have an app registered on Twitter! Note down the token and secret keys, and put them on the bottom of config/environment.rb, like this:
TWITTER_CONSUMER_KEY = 'YOUR_CONSUMER_KEY' TWITTER_CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET'
Now it’s time to integrate our app.














