Best practice for keeping streams alive

Apr 22, 2014 at 3:59 AM
I've noticed that every once in a while, my Filtered Stream will stop receiving data, but I'm not seeing any exceptions being thrown. I've worked with the streaming API in Python before and ran into this same thing. I ended up keeping a timestamp of the last time I received data, and checking it in another thread. If it went over a certain threshold, it would kill the stream and start a new one.

I was wondering if anyone had a better solution for keeping their streams alive? I'd prefer not to do it the same way with my current project - I'm receiving thousands of tweets per second and my old method seems too inefficient.
Apr 22, 2014 at 5:49 AM
Edited Apr 22, 2014 at 5:55 AM
private IFilteredStream _ts;

private void StartStream()
{
    _ts = Stream.CreateFilteredStream();

    _ts.StreamStopped +=
        (sender, args) =>
        {
            Thread.Sleep(2000);
            _ts.StartStreamMatchingAnyCondition();
        };

    _ts.AddFollow(_twitterMonitorUser, processTweet);
    _ts.StartStreamMatchingAnyCondition();
}
This is how I do it. However, you may want to follow twitter's guidelines for the wait time. Two seconds works well in my case.
Marked as answer by linvi on 4/22/2014 at 3:15 PM
Apr 22, 2014 at 4:10 PM
Thanks, that's exactly what I was looking for - I somehow didn't notice the StreamStopped event when I looked through the documentation!
Apr 30, 2014 at 6:10 PM
Hello.
I'm trying to implement the streaming but I can not get it to work.

Where I can find the right way to do it, I tried the dll documentation, but I fail to fucnione.

Working with c # or Vb.net.

My biggest problem is the Host authentication stream.twitter.com because the Host api.twitter.com I authenticate correctly.

Someone can help me?
Apr 30, 2014 at 9:12 PM
Hi,

Would you please be more precise on what you are trying to do.
To add credentials in Tweetinvi just use the following method with your credentials.
TwitterCredentials.SetCredentials("Access_Token", "Access_Token_Secret", "Consumer_Key", "Consumer_Secret");
When this is done you can access all the Twitter API from Tweetinvi and consequently the streaming API as followed.
var sampleStream = Stream.CreateSampleStream();
sampleStream.TweetReceived += (sender, args) => { Console.WriteLine(args.Tweet.Text); };
sampleStream.StartStream();
Please read the documentation for the examples.
If you need more complex access to the Streaming API please let me know and I will help you.

Regards,
Linvi
May 5, 2014 at 3:43 PM
Your message:

Hello!
I find examples, none works for me!
I need a working example or documentation more explicit ..
This is my code and does not work
Token string = "xxxxxxxxxxxxxxxx";
TokenSecret string = "xxxxxxxxxxxxxxx";
Consumerkey string = "xxxxxxxxxxxxxxx";
ConsumerSecret string = "xxxxxxxxxxxxxxxxx";
TwitterCredentials.SetCredentials (Token, TokenSecret, Consumerkey, ConsumerSecret);
Stream.CreateSampleStream sampleStream = var ();
sampleStream.TweetReceived + = (sender, args1) => {Console.WriteLine (args1.Tweet.Text); };
sampleStream.StartStream ();
Where am I wrong?
Thanks!
May 5, 2014 at 9:53 PM
Edited May 5, 2014 at 9:56 PM
Hello,

If your code does not throw any exception please look into the ExceptionHandler and send us the latest exceptions stored in your application.

Linvi
May 14, 2014 at 4:20 PM
Hello. My console application getting the streaming works perfectly.
I need to do the same but in an application that runs on a web server, but does not work me.

The code used is the same?

thank you very much!
May 15, 2014 at 11:52 AM
Would you please let me know what is going wrong?
Are you trying to implement the application in a WebService/ASP?

What error do you have in the ExceptionHandler?

Linvi
May 15, 2014 at 12:30 PM
Hi, I do not get any errors.
In the en request to the server never returns the answer.

filteredStream.MatchingTweetReceived + = (sender, args1) => {Response.Write (args1.Tweet.Text); };
             filteredStream.StartStreamMatchingAllConditions (); <- Here

Thank you very much!