开发者

OmniAuth invalid_response with Twitter

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 inva开发者_如何学编程lid 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.


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.


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.


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...


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


Have you tried omniauth-twitter gem?? https://github.com/arunagw/omniauth-twitter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜