Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: Filtered Stream not firing MatchingTweetReceived event handler

$
0
0
I'm trying to get the filtered stream to work in my code so I can search for hashtags in tweets. for example search tweets for the tag #btsno. Here's the snippet of the code in my program:
            // Twitter API Credentials - Removed for posting
            TwitterProfile profile = new TwitterProfile();
            profile.AccessToken = "...";
            profile.AccessTokenSecret = "...";
            profile.ConsumerKey = "...";
            profile.ConsumerSecret = "...";

            // Set credentials
            TwitterCredentials.SetCredentials(profile);

            // Create stream
            var filteredStream = Stream.CreateFilteredStream();

            // Add tracks to the stream
            filteredStream.AddTrack("btsno");
            filteredStream.AddTrack("%23btsno");
            filteredStream.AddTrack("#btsno");
            
            // Add event to be raised when a tweet is received
            //stream.MatchingTweetReceived += TweetReceived;
            filteredStream.MatchingTweetReceived += (sender, args) => {
                Console.WriteLine(args.Tweet.Text); 
            };

            // Start the stream in a new thread
            Thread t = new Thread(() =>
            {
                // Start the stream matching any of the conditions
                filteredStream.StartStreamMatchingAllConditions();
            });
            t.Start();
I've tried searching for hashtags in tweets and that works fine but the stream doesn't appear to work. Am I missing anything in my code or making a silly mistake somewhere?

Many thanks in advance

EDIT:
I've also tried using:
                 filteredStream.StartStreamMatchingAnyCondition();
EDIT:
It was a silly mistake. I forgot to start the thread, must be a morning coffee issue.
                  t.Start();
I'll leave the code here encase anyone needs it, otherwise linvi you may delete this thread.

Thanks for Tweetinvi it works like a charm!

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>