#11 ✓resolved
Lee Martin

status post throwing unauthorization error

Reported by Lee Martin | April 1st, 2009 @ 12:13 PM

My users login fine, but when trying to post to Twitter I get the following:

"TwitterAuth::Dispatcher::Unauthorized: The credentials provided did not authorize the user."

vendor/plugins/twitter-auth/lib/twitter_auth/dispatcher/shared.rb:23:in handle_response' vendor/plugins/twitter-auth/lib/twitter_auth/dispatcher/oauth.rb:22:inrequest' app/controllers/tracks_controller.rb:77:in post_status'

Using the README tip:

current_user.twitter.post('/statuses/update.json', 'status' => params[:status])

This error only occurs on my production server, works fine locally.

Comments and changes to this ticket

  • Lee Martin

    Lee Martin April 1st, 2009 @ 12:23 PM

    i should also note that this works fine locally

  • Lee Martin

    Lee Martin April 2nd, 2009 @ 12:57 AM

    upon closer examination, ive noticed the error is throw because of an html entity - in this case a music note

    i tried posting via HTTParty, which i was using in my app before moving to Twitter-Auth, and it worked fine

    im not too smart when it comes to these things, but could your json parser be throwing an error in relation to my music note?

  • Lee Martin

    Lee Martin April 2nd, 2009 @ 02:43 AM

    Here's a log comparison, ♫ vs ♫

    Local Machine

    Processing TracksController#post_status (for at 2009-04-01 20:36:33) [POST] Parameters: {"status"=>"ryan adams "wonderwall" ♫ http://twt.fm/54", "commit"=>"Tweet your track ♫", "authenticity_token"=>"..."} Completed in 16ms (View: 16, DB: 0) | 200 OK [http://localhost/post_status]

    Production Server

    Processing TracksController#post_status (for at 2009-04-02 06:34:07) [POST] Parameters: {"commit"=>"Tweet your track ♫", "authenticity_token"=>"...", "status"=>"ryan adams "wonderwall" ♫ http://twt.fm/22361"} Completed in 216ms (View: 0, DB: 2) | 200 OK [http://twt.fm/post_status]

  • Michael Bleigh

    Michael Bleigh April 4th, 2009 @ 10:58 PM


    I don't have too much experience with UTF-8 characters and the like. I'm open to any patches related to this issue but I'm not sure exactly what the problem is. When I have some time I'll see if I can experiment a bit myself. If it works locally, is there a difference perhaps in the encodings of a database on your production side?

  • Michael Bleigh

    Michael Bleigh April 10th, 2009 @ 02:31 AM

    • State changed from “new” to “resolved”

    This may actually have been a Twitter API issue: http://code.google.com/p/twitter...

    Can you try again and see if you're still having problems? Reopen if so.

  • Tiago Pinto

    Tiago Pinto May 30th, 2009 @ 10:08 AM

    Hi Michael,

    I just noticed this bug on 0.1.21 -- I tried to check with the internals of the gem without any luck. Hopefully you'll find it faster.

    I've installed the "twitter" gem and tried with it.

    with twitter_auth

    u = User.find(2)
    puts u.twitter.post("/statuses/update", :status => "testing ")

    this will give me the mentioned exception.

    with "twitter" gem

    require 'rubygems'
    require 'twitter'

    oauth = Twitter::OAuth.new(REDACTED, REDACTED)
    oauth.authorize_from_access(REDACTED, REDACTED)
    client = Twitter::Base.new(oauth)
    puts client.update("this will work ")

    it works.

    if there's anything i'm doing wrong, tell me.

    thanks for your work on twitter_auth.

  • Tiago Pinto

    Tiago Pinto May 30th, 2009 @ 10:10 AM

    i'm sorry for those headers. i forgot to wrap the whole thing inside a code block.

  • Tiago Pinto

    Tiago Pinto June 1st, 2009 @ 11:03 AM

    • Assigned user cleared.

    Fixed. I had frozen oauth-0.3.2 and everything started working when I updated the frozen gem to 0.3.4

    Keep up with the good work, Michael. Thanks for your work.

  • Levent

    Levent June 4th, 2009 @ 05:37 PM

    • Assigned user set to “Michael Bleigh”

    I'm getting this error with oauth 0.3.4 and oauth 0.3.5 in all environments

    First noticed trying to post a direct message to

    Any ideas?

    >>user.twitter.post("/statuses/update.json", {:status => "help me"})
    TwitterAuth::Dispatcher::Unauthorized: The credentials provided did not authorize the user.
        from /Users/levent/Projects/moodmapr/vendor/gems/twitter-auth-0.1.21/lib/twitter_auth/dispatcher/shared.rb:23:in `handle_response'
        from /Users/levent/Projects/moodmapr/vendor/gems/twitter-auth-0.1.21/lib/twitter_auth/dispatcher/oauth.rb:22:in `request'
        from /Users/levent/Projects/moodmapr/vendor/gems/oauth-0.3.5/lib/oauth/tokens/access_token.rb:44:in `post'
        from (irb):3
  • Chris O'Sullivan

    Chris O'Sullivan June 8th, 2009 @ 05:42 AM

    I'm suffering from the same problem as Levent - I keep getting "The credentials provided did not authorize the user" when posting a status to Twitter.

    Any ideas?

  • Levent

    Levent June 9th, 2009 @ 07:07 PM

    • Assigned user cleared.

    Hi Chris,

    It seems to be a bug with twitter itself

    If you created your app in twitter as read only you need to delete and recreate it again as read+write

    Unfortunately editing and changing your app settings from read to read+write just doesn't seem to work

    Check this ticket:

    Don't forget your consumer key and consumer secret will change when you do this

  • Elad Meidar

    Elad Meidar July 6th, 2009 @ 04:14 PM

    • Assigned user set to “Michael Bleigh”

    Seriously ? i have to delete my app ? what about all the users i have?

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A full-stack authentication system for Rails that uses Twitter.