我正在使用 Rails 应用程序的 twitter gem,这样我就可以将我的博客文章自动更新到我的 twitter feed 上。
我关注了gem readme instructions ,将其放入 config/initializers/twitter.rb 文件中
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
将这些变量更新到 Heroku,在我的 Twitter 帐户下注册我的应用程序,授予该帐户读取、写入和直接访问权限,然后尝试通过 Heroku 控制台进行更新,如下所示:
Twitter.update("Testing Twitter integration")
不幸的是,我收到此错误:
Twitter::Error::Unauthorized: Could not authenticate you
(后面是这些可能无用的细节):
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter/response/raise_error.rb:21:in `on_complete'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/response.rb:9:in `block in call'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/response.rb:63:in `on_complete'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/response.rb:8:in `call'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/request/url_encoded.rb:14:in `call'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/request/multipart.rb:13:in `call'
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter/request/multipart_with_file.rb:14:in `call'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/connection.rb:247:in `run_request'
from /app/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.6/lib/faraday/connection.rb:112:in `post'
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter/client.rb:81:in `request'
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter/client.rb:70:in `post'
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter/api/utils.rb:82:in `object_from_response'
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter/api/tweets.rb:129:in `update'
from /app/vendor/bundle/ruby/1.9.1/gems/twitter-4.5.0/lib/twitter.rb:52:in `method_missing'
from (irb):2
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):003:0>
Twitter 肯定至少部分地验证了我的身份,因为早些时候,当我没有切换到读/写模式时,它提示说
Twitter::Error::Unauthorized: Error processing your OAuth request: Read-only application cannot POST
(为了解决此问题,我编辑了设置并重置了 OAuth key )。
我用 Google 搜索过,但没有找到处于相同情况的其他人。想知道我是否做错了什么,或者我是否需要等待一段时间。
有什么想法吗?
最佳答案
您是否提供了回调网址?
这发生在 Twitter 的新更新中,即使我没有使用应用程序配置中的回调 url,我也遇到了同样的问题,直到我更新它,我结束了添加
http://www.my-website.com/auth/twitter/callback
我什至没有将其用于本地主机开发,但之后它就开始工作了。
否则,请使用您的 Twitter 身份验证代码/ gem 以及您在 Twitter 上的设置更新问题,以便我们可以审查代码并让您知道是否有问题
关于ruby-on-rails - 推特 "could not authenticate you"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15146767/