gpt4 book ai didi

ruby - 使用 tweetstream 和超时

转载 作者:数据小太阳 更新时间:2023-10-29 07:38:04 26 4
gpt4 key购买 nike

ruby 版本:2.0.0-p0Mac - 山狮

以下是我的代码(tw_stream_track.rb):

require 'tweetstream'

TweetStream.configure do |config|
config.consumer_key = 'xxxxxxxxxxxxxxx'
config.consumer_secret = 'xxxxxxxxxxxxxxx'
config.oauth_token = 'xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx'
config.oauth_token_secret = 'xxxxxxxxxxxxxxx'
config.auth_method = :oauth
end

client = TweetStream::Client.new

client.on_error do |message|
puts message
end

client.track('apple', 'microsoft', 'samsung') do |status|
puts "#{status.text}"
end

当我从终端运行它时:

ruby tw_stream_track.rb

我得到以下信息:

/Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/tweetstream-2.5.0/lib/tweetstream/client.rb:436:in `block in connect': Failed to reconnect after 11 tries. (TweetStream::ReconnectError)
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/em-twitter-0.2.2/lib/em-twitter/connection.rb:296:in `call'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/em-twitter-0.2.2/lib/em-twitter/connection.rb:296:in `invoke_callback'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/em-twitter-0.2.2/lib/em-twitter/connection.rb:268:in `rescue in schedule_reconnect'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/em-twitter-0.2.2/lib/em-twitter/connection.rb:263:in `schedule_reconnect'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/em-twitter-0.2.2/lib/em-twitter/connection.rb:93:in `unbind'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1440:in `event_callback'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/tweetstream-2.5.0/lib/tweetstream/client.rb:388:in `start'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/tweetstream-2.5.0/lib/tweetstream/client.rb:131:in `filter'
from /Users/mine/.rvm/gems/ruby-2.0.0-p0/gems/tweetstream-2.5.0/lib/tweetstream/client.rb:98:in `track'

这是我第一次使用 tweetstream,从文档来看,这似乎是我应该做的。我错过了什么?

最佳答案

我听说 TweetStream 在 ruby​​ 2.0.0 上有一些问题,你试过 ruby​​ 1.9.3 了吗?

更新

我刚刚试了一下,您的代码在 ruby​​ 1.9.3(随 rvm 一起安装)上运行良好。我唯一拥有的 pb 是流似乎在一段时间后停止检索新消息。

关于ruby - 使用 tweetstream 和超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16247060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com