Reputation: 460
Using OmniAuth, Rails 3.1.0.rc2, mysql2, ruby 1.9.2.p0.
I still get this when redirecting back to my site.
/auth/failure?message=invalid_response
Omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, 'XXXXX', 'XXXXXXXXXXXXX'
I've checked the keys 100x and they are correct. Still getting the invalid response. Any of the questions I see don't seem to work.
Any help would be greatly appreciated!
Thanks. [:
If any new information is needed, just ask.
Upvotes: 4
Views: 3555
Reputation: 1193
Have you tried omniauth-twitter gem?? https://github.com/arunagw/omniauth-twitter
Upvotes: 0
Reputation: 38
Thank you Christian for your answer. It was very helpful for me. But if it gives a 401 error trying to update, retweet, etc you will have to include
config.oauth_token = 'MY_OAUTH_TOKEN'
config.oauth_token_secret = 'MY_OAUTH_TOKEN_SECRET'
to Twitter client configuration. Look at https://dev.twitter.com/discussions/1522
So finally you will have
Twitter.configure do |config|
config.consumer_key = 'TW_CONSUMER_KEY'
config.consumer_secret = 'TW_CONSUMER_SECRET'
config.oauth_token = 'MY_OAUTH_TOKEN'
config.oauth_token_secret = 'MY_OAUTH_TOKEN_SECRET'
end
It worked for me
and of course your Twitter app has to have Access level = Read and write. You have to change this in dev.twitter.com if you want to update the status, retweet, etc
Upvotes: 0
Reputation: 682
I had a similar problem. It turns out that I actually had some runtime errors in my Users::OmniauthCallbacksController#twitter method:
I was calling a method on a non-existent method on a nil object and this was raising an exception, but either devise or omniauth were swallowing the exception.
I ended up wrapping my entire method body in a begin/rescue clause and printing out the exception.
However, if you are getting Invalid Credentials then it's likely that the twitter-issued oauth key has expired and so your user should really be calling /users/auth/twitter again.
Upvotes: 4
Reputation: 4113
If you use this request.env['rack.auth']
in your controller, change this to request.env['omniauth.auth']
- this were explained here OmniAuth
this solution works for me.
Upvotes: 4
Reputation: 1892
Are you sure you are not putting the keys in the wrong order?
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, TW_CONSUMER_KEY, TW_CONSUMER_SECRET
end
If not, let's quickly test your credentials with the Twitter gem:
# twitter.rb -- Test credentials
require "rubygems"
require "twitter"
# Get a user's most recent status update
puts Twitter.user_timeline("YOUR_USER").first.text
Twitter.configure do |config|
config.consumer_key = TW_CONSUMER_KEY
config.consumer_secret = TW_CONSUMER_SECRET
end
# Update your status
Twitter.update("I Love ruby!")
If it works, then your credentials are fine... you should keep looking into Rails...
Upvotes: 3