Twitter::Error::Forbidden - Unable to verify your credentials

梦想与她 提交于 2020-01-06 04:35:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!