问题
I'm using devise + omniauth and I can connect to twitter api correctly.
But when I try to use twitter gem, I have the following error in console :
"Twitter::Error::Forbidden - Unable to verify your credentials"
I have installed the gem and created an initializer at config/initializers/twitter.rb
Twitter.configure do |config|
config.consumer_key = PKe41...
config.consumer_secret = qETY.....
end
And I'm trying into a controller :
def twitter
@twitter_home_timeline = Twitter.home_timeline
end
回答1:
Ok, I found the answer... Keys in the initializer must be set with quotation marks :
Twitter.configure do |config|
config.consumer_key = 'PKe41...'
config.consumer_secret = 'qETY.....'
end
回答2:
You also need to add oauth token and secret If you don't, you just give two credentials of an account. It can't find the correct app used for these credentials.
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
来源:https://stackoverflow.com/questions/17719358/twittererrorforbidden-unable-to-verify-your-credentials