Can we know for which track keyword we receive a tweet message?


#1

Dear All,

I am working on a streaming project where I have a tricky requirement, question is

I have put 4 hashtags as a parameters, on which i have started the stream. e.g. #movie, #songs, #test, #news. the stream gets started and I am beginning to receive messages in the stream.

Can I know that which message i receive as a result of which hashtag ???

e.g. I have received a message as a result of #movies match in the twitter message text. I am using regular expression to again find that what was the track keyword. Bu my question is from twitter streaming can i know exactly, that this tweet is returned as a result of #movies ??

Any help in this regards will be highly appreciated.

Thanks

Eman


#2

Unfortunately no, the way to figure out what matched a tweet is the way you’re doing it - matching strings your self.

You might also want to check expanded_url, and screen_name for matches just in case: https://dev.twitter.com/streaming/overview/request-parameters#track

The text of the Tweet and some entity fields are considered for matches. Specifically, the text attribute of the Tweet, expanded_url and display_url for links and media, text for hashtags, and screen_name for user mentions are checked for matches.


#3

Thanks Igor for the answer. :slight_smile:


#4

Hi there,

If you are using C#, Tweetinvi will do that for you.

var stream = Stream.CreateFilteredStream();

// Add all your filters with AddTrack
stream.AddTrack("tweetinvi");
stream.AddTrack("rest");

stream.MatchingTweetReceived += (sender, args) =>
{
    // This event will be invoked every time a tweet created is matching your criteria
    var tweet = args.Tweet;

    // If you want to get all the matching values
        var matchingTracks = args.MatchingTracks;
        var matchingFollowers = args.MatchingFollowers;
        var matchingLocations = args.MatchingLocations;

        // If you want to know which criteria has matched
        var matchedOn = args.MatchOn;

        // MatchOn can be TweetText or HashTagEntities for example
};

stream.StartStreamMatchingAllConditions();

#5

Good One that’s what i wanted.

and Yes I am using TweetInv for streaming… your solution works perfect

Thanks Again TweetInvAPI :slight_smile: