title: Keep getting OAuth::Unauthorized error when using oauth and twitter ruby gems
body: <p>I am using the ruby twitter gem and oauth to gain access to users twitter accounts.  In my code, I have:</p>
  
  <pre><code>unless @user.twitter_authd?
        oauth = Twitter::OAuth.new('token', 'secret')
        session[:twitter_request_token] = oauth.request_token.token
        session[:twitter_request_secret] = oauth.request_token.secret
        @twitter_auth_url = oauth.request_token.authorize_url
      end
  </code></pre>
  
  <p>where token and secret have my actual token and secret inserted.  When I click on the link to the @twitter_auth_url, I am taken to twitter and asked to grant access.  I click allow and then twitter redirects me to my callback URL <a href="http://www.mydomain.com/twitter_callback/?oauth_token=fmy2aMvnjVgaFrz37bJ4JuB8r5xN79gsgDQRG4BNY" rel="noreferrer">http://www.mydomain.com/twitter_callback/?oauth_token=fmy2aMvnjVgaFrz37bJ4JuB8r5xN79gsgDQRG4BNY</a> which then hits this code:</p>
  
  <pre><code>oauth = Twitter::OAuth.new('token', 'secret')
  
      logger.info("session[:twitter_request_token] = #{session[:twitter_request_token]}")
      logger.info("session[:twitter_request_secret] = #{session[:twitter_request_secret]}")
  
      oauth.authorize_from_request(session[:twitter_request_token], session[:twitter_request_secret])
      session[:twitter_request_token] = nil
      session[:twitter_request_secret] = nil
  
      @user.update_attributes({
        :twitter_token =&gt; oauth.access_token.token, 
        :twitter_secret =&gt; oauth.access_token.secret,
      })
  
      redirect_to root_path
  </code></pre>
  
  <p>The twitter request token and secret are being set just fine.  However I end up with an authorization error:</p>
  
  <pre><code> OAuth::Unauthorized in MainController#twitter_callback
  
  401 Unauthorized
  
  RAILS_ROOT: /Users/TAmoyal/Desktop/RoR_Projects/mls
  Application Trace | Framework Trace | Full Trace
  
  /Library/Ruby/Gems/1.8/gems/oauth-0.3.4/lib/oauth/consumer.rb:167:in `token_request'
  /Library/Ruby/Gems/1.8/gems/oauth-0.3.4/lib/oauth/tokens/request_token.rb:14:in `get_access_token'
  /Library/Ruby/Gems/1.8/gems/erwaller-twitter-0.6.13.1/lib/twitter/oauth.rb:29:in `authorize_from_request'
  /Users/TAmoyal/Desktop/RoR_Projects/mls/app/controllers/main_controller.rb:70:in `twitter_callback'
  </code></pre>
  
  <p>The code is failing at this line:</p>
  
  <pre><code>oauth.authorize_from_request(session[:twitter_request_token], session[:twitter_request_secret])
  </code></pre>
  
  <p>when it tries to get an access token.  You can see the source code of authorize_from_request <a href="http://twitter.rubyforge.org/rdoc/classes/Twitter/OAuth.html#M000031" rel="noreferrer">here</a>.  I am not sure why this is happening.  Anyone have ideas?</p>