0

I use tweetstream gem to get sample tweets from Twitter Streaming API:

TweetStream.configure do |config|
    config.username = 'my_username'
    config.password = 'my_password'
    config.auth_method = :basic
end

@client = TweetStream::Client.new

@client.sample do |status|
    puts "#{status.text}"
end

However, this script will stop printing out tweets after about 100 tweets (the script continues to run). What could be the problem?

Alex Bitek
  • 6,529
  • 5
  • 47
  • 77
daisy
  • 47
  • 1
  • 8

1 Answers1

0

The Twitter Search API sets certain arbitrary (from the outside) limits for things, from the docs:

GET statuses/:id/retweeted_by Show user objects of up to 100 members who retweeted the status.

From the gem, the code for the method is:

# Returns a random sample of all public statuses. The default access level
# provides a small proportion of the Firehose. The "Gardenhose" access
# level provides a proportion more suitable for data mining and
# research applications that desire a larger proportion to be statistically
# significant sample.
def sample(query_parameters = {}, &block)
  start('statuses/sample', query_parameters, &block)
end

I checked the API docs but don't see an entry for 'statuses/sample', but looking at the one above I'm assuming you've reached 100 of whatever statuses/xxx has been accessed.

Also, correct me if I'm wrong, but I believe Twitter no longer accepts basic auth and you must use an OAuth key. If this is so, then that means you're unauthenticated, and the search API will also limit you in other ways too, see https://dev.twitter.com/docs/rate-limiting

Hope that helps.


Ok, I made a mistake there, I was looking at the search API when I should've been looking at the streaming API (my apologies), but it's possible some of the things I was talking about could be the cause of your problems so I'll leave it up. Twitter definitely has moved away from basic auth, so I'd try resolving that first, see:

https://dev.twitter.com/docs/auth/oauth/faq

ian
  • 12,003
  • 9
  • 51
  • 107
  • Thanks for your detail answer. I did tried OAuth, then I get an error: `Failed to reconnect after 7 tries`.After searching Google, I found this [issues](https://github.com/intridea/tweetstream/issues/50) which suggest to switch back to basic authentication. What should I do? – daisy Jan 04 '12 at 08:53
  • 1
    You might try a different twitter gem or use the Oauth gem to test your credentials. I see there's also a twitter_oauth gem you could try https://github.com/moomerman/twitter_oauth#readme. If you get the same trouble it's probably Twitter. I went through the process of writing my own Oauth and Twitter connection script, not using gems, a while back. If you're still having trouble after trying the other gems let me know and I'll post up the code for you to try. – ian Jan 04 '12 at 18:31
  • 1
    You might also check the https://dev.twitter.com/status page whenever you run it. I thought there was a way to check this programmatically in one of the API's but I can't find it. – ian Jan 04 '12 at 18:35