How to keep streaming continuously - Tweetinvi

。_饼干妹妹 提交于 2019-12-07 12:54:42

问题


I adapted the following code from one I found online. Works ok but is not running continuously and pulling in new tweets. What do I need to change? Help appreciated.

private static void Stream_FilteredStreamExample()
{
    SqlConnection conn = new SqlConnection(@"Data Source=********************");
    conn.Open();

    for (; ; )
    {
        try
        {
            var stream = Stream.CreateFilteredStream();
            //stream.AddLocation(Geo.GenerateLocation(-180, -90, 180, 90));
            stream.AddTweetLanguageFilter(Language.English);
            stream.AddTrack("#TubeStrike");

            var timer = Stopwatch.StartNew();

            stream.MatchingTweetReceived += (sender, args) =>
            {

                var tweet = args.Tweet;

                if (timer.ElapsedMilliseconds > 1000)
                {
                    Console.WriteLine("{0}, {1}", tweet.IdStr, tweet.Text);
                    timer.Restart();
                }
            };

            stream.StartStreamMatchingAllConditions();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception: {0}", ex.Message);
        }
    }
}

回答1:


You want to use the following code:

stream.StreamStopped += (sender, args) =>
{
     stream.StartStreamMatchingAllConditions();
};


来源:https://stackoverflow.com/questions/31319449/how-to-keep-streaming-continuously-tweetinvi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!