Attempting to get a filtered stream using the Tweetinvi library via c#.
I am trying to do something similar to the search, which I have been able to successfully receive tweets:
public List<ITweet> SearchTweets(string query)
{
List<ITweet> tweets = new List<ITweet>();
TwitterCredentials.ExecuteOperationWithCredentials(Credentials, () =>
{
var searchParam = Search.GenerateSearchTweetParameter(query);
searchParam.Lang = Language.English;
searchParam.MaximumNumberOfResults = 100;
tweets = Search.SearchTweets(searchParam);
});
return tweets;
}
but the limitation here is that I can only get a max 100 tweets. I want to leverage the stream in a similar way and get a stream of tweets matching the tracks that I pass. I have tried this:
public void FilterStream(string query)
{
IFilteredStream tweets;
TwitterCredentials.ExecuteOperationWithCredentials(Credentials, () =>
{
var filteredStream = Tweetinvi.Stream.CreateFilteredStream();
filteredStream.AddTrack(query);
filteredStream.AddTrack("#" + query);
filteredStream.MatchingTweetReceived += (sender, args) => { Debug.WriteLine(args.Tweet.Text); };
filteredStream.StartStreamMatchingAllConditions();
});
}
but problem is it seems to run in an infinite loop and i'm unsure where to stop or limit the number of tweets I received from the stream to make it stop. The library's documentation is quite unclear and I have been unable to achieve the behavior I am seeking. I'm sure I am on the right route, just unsure how to stop the stream and store all the tweets I've received in a List<ITweet> construct.
To stop the stream use:
You can keep a count of the tweets globally then stop when the number of tweets you need is received.