我正在使用twitter gem和amniauth来获取用户的推文并在我的主页上显示它们。但是当我尝试从命令行抓取推文时,我收到了“错误的身份验证数据”错误。
的Gemfile:
gem 'omniauth'
gem 'omniauth-twitter'
gem 'twitter'
配置/初始化程序中的Twitter.rb:
Twitter.configure do |config|
config.consumer_key = 'key'
config.consumer_secret = 'secret'
config.oauth_token = 'token'
config.oauth_token_secret = 'secret'
end
config / initializers中的omniauth.rb:
require 'omniauth-twitter'
config.omniauth :twitter, 'key', 'secret'
我已经仔细检查了我的密钥和密码,但我无法让它运行。我正在使用Spree。这是错误:
irb(main):001:0> require 'twitter'
=> true
irb(main):002:0> Twitter.user_timeline(213747670)
Twitter::Error::BadRequest: Bad Authentication data
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/response/raise_error.rb:21:in `on_complete'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/response.rb:9:in `block in call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/response.rb:63:in `on_complete'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/request/url_encoded.rb:14:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/request/multipart.rb:13:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/request/multipart_with_file.rb:14:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/connection.rb:247:in `run_request'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/connection.rb:100:in `get'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/client.rb:81:in `request'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/client.rb:64:in `get'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/api/utils.rb:51:in `objects_from_response'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/api/utils.rb:42:in `objects_from_response_with_user'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/api/timelines.rb:53:in `user_timeline'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter.rb:52:in `method_missing'
from (irb):2
感谢您的帮助。
答案 0 :(得分:0)
要获取并显示用户的推文,最好使用 twitter gem 请参阅以下链接以获取分步说明