Using Twitter and Timeout

Ruby version: 2.0.0-p0 Mac - Mountain Lion

Below is my code (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 

When I run it from the terminal:

 ruby tw_stream_track.rb 

I get the following:

 /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' 

This is my first time using tweetstream, and from the documentation it seems like this is what I should be doing. What am I missing?

+4
source share
2 answers

I heard that TweetStream had problems with ruby ​​2.0.0, have you tried with ruby ​​1.9.3?

UPDATE

I just had a try and your code works fine with ruby ​​1.9.3 (installed with rvm). The only pb I have is that the thread seems to stop receiving new messages after a while.

+1
source

In my case, this error occurred because I used the same keys in two instances of rails applications (on intermediate and production servers) + 1 local (development) instance.

The third instance could not connect to the stream of tweets. This is due to twitter restrictions.

So, I solved this by creating custom Twitter applications (with separate keys) for each instance of the Rails application.

0
source

All Articles