Public Streaming API Rate Limit?

Nov 12, 2014 at 6:34 PM

I'm working on a project utilizing Twitter's Public Streaming API and all is working well - successfully subscribing to keywords/tracks and receiving tweets flawlessly.

I'd like to make my application a bit more robust and inform the user if they are rate-limitted by twitter. Apparently this can happen if more than one connection is made to the Public API. How can I safeguard against violating this guideline, and where would be an appropriate location (in code) to inform the user? Can I subscribe to a RateLimit event here?

Please let me know any thoughts, thanks for taking the time!
Nov 12, 2014 at 8:13 PM
May I ask - are you using a user stream or a filtered stream? I'm trying to use both in the same application (1 of each if it matters to anyone reading) but my filter stream doesn't seem to be working.
            IFilteredStream fs = Stream.CreateFilteredStream();
            fs.AddTrack("@markadrake join");
            fs.AddTrack("@markadrake remove");
            fs.AddTrack("@markadrake add");
            fs.AddTrack("@markadrake delete");
            fs.MatchingTweetReceived += (s, a) =>
                Console.WriteLine("{0} wrote: {1}", a.Tweet.Creator.ScreenName, a.Tweet.Text);
I'm basically adding or removing someone to a list if they use some keywords. But I have people testing, and it's not firing off the event.
Nov 12, 2014 at 8:14 PM
Filtered stream
Nov 13, 2014 at 12:45 AM

I don't remember on top of my head how Twitter notifies that the rate limit has been reached for a Stream.
But please try using the information from the events DisconnectMessageReceived and StreamStopped
fs.DisconnectMessageReceived += (sender, args) => { Console.WriteLine(args.DisconnectMessage); };
fs.StreamStopped += (sender, args) => { Console.WriteLine(args.Exception.ToString() + ' - ' + args.DisconnectMessage); };
Nov 13, 2014 at 1:28 AM
Thanks Linvi, will give the above code a shot
Nov 13, 2014 at 2:09 AM
Linvi -

I've implemented the suggested code and am noticing the following exception being thrown on the StreamStopped event
System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
   at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
   at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Tweetinvi.Streams.Helpers.StreamResultGenerator.<StartStreamAsync>d__7.MoveNext()
Is this normal and should I just remedy by restarting the filtered stream? The one filtered stream contains around 300 tracks.

Thanks again for taking the time
Nov 13, 2014 at 9:38 AM

If I understand correctly, you are explaining that the StreamStopped event is raised and the arguments contains the Exception thatyou are showing me?

If this is the case then, the answer is yes.
var fs = Stream.CreateFilteredStream();
fs.StreamStopped += (sender, args) =>
    if (args.Exception != null)
Marked as answer by bmn080706 on 11/13/2014 at 8:47 AM