Stream endpoint /statuses/filter.json API returns 401 'sometimes'



I have been using the streaming API with the basic auth for more than a year without any issue, but now I switched to oauth and I’ve got some serious problem.

I am using Ruby+TweetStream, and the code is quite straightforward:

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

client =
client.locations(-180, -90, 180, 90) do |tweet|
puts tweet

oauth_token & oauth_token_secret are the ones generated for the application.

My problem is simple and very weird: after a minute or less streaming tweets just fine, I get a 401 error. If I try to restart the stream doesn’t start anymore. I have to wait 5-10 mins to get it working again, but only for just another minute.
This is really annoying and I don’t have any idea what the cause could be.

Did anyone experience this behaviour too or maybe can spot an error in my code?


PS: I switched to the oauth authentication as the basic one didn’t work anymore (always straight 401 error). Tried with different users.