OAuth with the Twitter Gem

by Charles Max Wood on October 6, 2010

Twitter just turned off Basic Auth and is forcing application developer to use OAuth. Here is a demonstration of how to add Twitter OAuth to your Ruby on Rails Application.

Download 90.9 MB
Download (iPod & iPhone) 45.6 MB

  • Igbanam Ogbuluijah

    Man, you are a saviour. I almost pulled the last strand of my bald hair out trying to figure this out from the code the Twitter gem provides.

    Thanks!

    • http://teachmetocode.com Charles Max Wood

      Glad it helped. I know what it’s like to be losing your hair. It doesn’t help when you’re pulling it out over something like this.

      Any other ways I can preserve your diminishing hair?

  • Igbanam Ogbuluijah

    Man, you are a saviour. I almost pulled the last strand of my bald hair out trying to figure this out from the code the Twitter gem provides.

    Thanks!

    • http://teachmetocode.com Charles Max Wood

      Glad it helped. I know what it’s like to be losing your hair. It doesn’t help when you’re pulling it out over something like this.

      Any other ways I can preserve your diminishing hair?

  • http://www.getmeacustomer.com Tzuming

    hey buddy, great stuff. Just wanted to let you know that perhaps you should name your page titles and seo your entries so people can find them easier – there are tonnes of people just looking to solve this problem. take care.

  • http://www.getmeacustomer.com Tzuming

    hey buddy, great stuff. Just wanted to let you know that perhaps you should name your page titles and seo your entries so people can find them easier – there are tonnes of people just looking to solve this problem. take care.

  • http://www.getmeacustomer.com Tzuming

    silly question, how does the ‘finalize’ action get triggered in the controller in this case, was it routed manually or by default?

    • http://teachmetocode.com Charles Max Wood

      The finalize action is set in the .set_callback_url call.

  • http://www.getmeacustomer.com Tzuming

    silly question, how does the ‘finalize’ action get triggered in the controller in this case, was it routed manually or by default?

    • http://teachmetocode.com Charles Max Wood

      The finalize action is set in the .set_callback_url call.

  • Andrew

    Great video!

    Just thought I would point out Twitter::OAuth was removed in newer versions of the gem.

    http://groups.google.com/group/ruby-twitter-gem/browse_thread/thread/be600e4ffc5f6646#

  • Andrew

    Great video!

    Just thought I would point out Twitter::OAuth was removed in newer versions of the gem.

    http://groups.google.com/group/ruby-twitter-gem/browse_thread/thread/be600e4ffc5f6646#

  • http://twitter.com/laurentk Laurent Kretz

    Hi Charles, thx for the screen cast.
    I’m a total noob (in ror) and get stuck in the middle of the tutorial (uninitialized constant TwitterController::Twitter).

    Just to make sure i’m not crazy, which Twitter Gem are you using ?

    Thx !

    • http://teachmetocode.com Charles Max Wood

      I’m using the Twitter gem.

      In your Gemfile, you should see:

      gem ‘twitter’

      • http://twitter.com/laurentk Laurent Kretz

        Hi Charles,
        Thx for the quick answer. As said, i’m a noob and jumping from tutos to tutos, i missed the main one : gem install [gem] needs a gemfile modif and a bundle install :)
        Thx again !

        • http://teachmetocode.com Charles Max Wood

          Yes, in Rails 3, you’ll need to modify your Gemfile and then run `bundle install` to get the gem included.

  • http://twitter.com/laurentk Laurent Kretz

    Hi Charles, thx for the screen cast.
    I’m a total noob (in ror) and get stuck in the middle of the tutorial (uninitialized constant TwitterController::Twitter).

    Just to make sure i’m not crazy, which Twitter Gem are you using ?

    Thx !

    • http://teachmetocode.com Charles Max Wood

      I’m using the Twitter gem.

      In your Gemfile, you should see:

      gem ‘twitter’

      • http://twitter.com/laurentk Laurent Kretz

        Hi Charles,
        Thx for the quick answer. As said, i’m a noob and jumping from tutos to tutos, i missed the main one : gem install [gem] needs a gemfile modif and a bundle install :)
        Thx again !

        • http://teachmetocode.com Charles Max Wood

          Yes, in Rails 3, you’ll need to modify your Gemfile and then run `bundle install` to get the gem included.

  • Drew Berkowitz

    Charles, this is a great tutorial! However part of the functionality is no longer there because the Twitter::OAuth class has been removed.

    “The Twitter::OAuth class has been removed. This class was just a wrapper to
    get access tokens via the oauth gem. Given that there are a variety of gems
    that do the same thing (twitter-auth, omniauth, and devise, to name a few)
    we decided to decouple this functionality so you can use the authentication
    library of your choosing, or none at all. ”

    What type of fix would this require to get your solution working again? Thanks for the help.

    • http://teachmetocode.com Charles Max Wood

      Drew, I’ve done similar stuff with the twitter_oauth gem. https://github.com/moomerman/twitter_oauth

      I’ve also used the oauth gem, but it takes a little more plumbing to get it working.

  • Drew Berkowitz

    Charles, this is a great tutorial! However part of the functionality is no longer there because the Twitter::OAuth class has been removed.

    “The Twitter::OAuth class has been removed. This class was just a wrapper to
    get access tokens via the oauth gem. Given that there are a variety of gems
    that do the same thing (twitter-auth, omniauth, and devise, to name a few)
    we decided to decouple this functionality so you can use the authentication
    library of your choosing, or none at all. ”

    What type of fix would this require to get your solution working again? Thanks for the help.

    • http://teachmetocode.com Charles Max Wood

      Drew, I’ve done similar stuff with the twitter_oauth gem. https://github.com/moomerman/twitter_oauth

      I’ve also used the oauth gem, but it takes a little more plumbing to get it working.

Previous post:

Next post: