Ruby的Twitter REST api不起作用

时间:2014-01-11 21:15:41

标签: ruby twitter

我正在尝试使用twitter api的ruby接口.Streaming Api正在工作,但Rest spi不工作。

代码:

require 'rubygems'
require 'twitter'

client = Twitter::REST::Client.new do |config|
  # you must set up an application using Twitter's developer site, and set these values:
  # (See the Configuration example)
  config.consumer_key        = "xxx"
  config.consumer_secret     = "xxx"
  config.access_token        = "xxx-xxx"
  config.access_token_secret = "xxx"
end

puts client.user('xyz')

我总是收到以下错误 -

Faraday::Builder is now Faraday::RackBuilder.
/home/atul/.rvm/gems/ruby-2.1.0/gems/twitter-5.5.1/lib/twitter/rest/client.rb:143:in `rescue in request': execution expired (Twitter::Error)
from /home/atul/.rvm/gems/ruby-2.1.0/gems/twitter-5.5.1/lib/twitter/rest/client.rb:131:in `request'
from /home/atul/.rvm/gems/ruby-2.1.0/gems/twitter-5.5.1/lib/twitter/rest/client.rb:97:in `get'
from /home/atul/.rvm/gems/ruby-2.1.0/gems/twitter-5.5.1/lib/twitter/rest/api/utils.rb:118:in `object_from_response'
from /home/atul/.rvm/gems/ruby-2.1.0/gems/twitter-5.5.1/lib/twitter/rest/api/users.rb:257:in `user'
from actresses.rb:17:in `<main>'

我正试图通过this解决方案来增加时间,但我能够弄清楚如何做到这一点。 我不明白我做错了什么,因为相同的代码在进行适当的更改后正在为Streaming api工作。

1 个答案:

答案 0 :(得分:0)

我不清楚你遇到了什么样的问题,但要设置超时你可能想尝试

custom_options = Twitter::Default::CONNECTION_OPTIONS.merge(
                          request: { open_timeout: 5, timeout: 20 } )  # default timeout is 10

client = Twitter::REST::Client.new do |config|
  # you must set up an application using Twitter's developer site, and set these values:
  # (See the Configuration example)
  config.consumer_key        = "xxx"
  config.consumer_secret     = "xxx"
  config.access_token        = "xxx-xxx"
  config.access_token_secret = "xxx"
  config.connection_options  = custom_options
end
但是,我不确定这是否会解决该错误。