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

New Post: Do we able to get keyword searched from the tweets by using Search.SearchTweets()?

$
0
0
Hi there,

Sorry for taking so much time to reply to your post. I usually respond within hours but I have been working a lot lately.

This feature is something that you have to implement by doing a simple regex/search over the Tweet.Text foreach of your keyworkds.
// This code can be improved for performancesvar keywords = new[] { "obama", "apple" };
var search = keywords[0];
keywords.ForEach(x => search += "OR" + x);

var tweets = Search.SearchTweets(search);

foreach (var tweet in tweets)
{
    foreach (var keyword in keywords)
    {
        if (tweet.Text.Contains(keyword))
        {
            // Your code here to manage it
        }
    }
}
Though, if you are willing to use the Stream API, Tweetinvi does that for you.
var keywords = new[] { "obama", "apple" };
var stream = Stream.CreateFilteredStream();
            
foreach (var keyword in keywords)
{
    stream.AddTrack(keyword);
}
            
stream.MatchingTweetReceived += (sender, args) =>
{
    var matchingKeywords = args.MatchingTracks;
    var tweet = args.Tweet;
};

stream.StartStreamMatchingAllConditions();
Kind Regards,
Linvi

Viewing all articles
Browse latest Browse all 4126

Trending Articles



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