Stream tweets which mention @friendname

1.1k Views Asked by At

I have a C# application that streams all tweets created by any of my friends successfully (using Tweetinvi library and following code).

var userStream = Tweetinvi.Stream.CreateUserStream();

userStream.TweetCreatedByFriend += (sender, args) =>
{
    ConsoleLog(args.Tweet.Text);
}

How (if possible) can I listen to the tweets which mention any of my friends' screen name ? e.g. I am friend with @alice. Now @bob, who is NOT my friend, tweets like this:

Hi @alice, how are you ?

How can I listen to above tweet by @bob, who is NOT my friend, and MAY or MAY NOT be friend or follower of @alice?

2

There are 2 best solutions below

3
On

You cannot do that. Or at least I don't think you can if you have too many friends. The only solution you currently I currently can see is to use the FilteredStream because it is a public stream and you can access tweets from users that your are not following.

If the list of followers you have is low enough you can do the following

var fs = Stream.CreateFilteredStream();
fs.AddTrack("@userScreenName");

As a result you'll be able to follow all the tweets containing @userScreenName from any user of Twitter.

0
On

I know this is a very old question but try using a UserStream and filtering out the UserMentions. I'm right now trying to find a better way of doing this myself. Everytime a user mentions you, they are added to your UserStream.

var stream = Tweetinvi.Stream.CreateTweetStream();
stream.TweetReceived += (sender, args) =>
{
         if(args.Tweet.IsRetweet || !args.Tweet.UserMentions.Any((x)=> x.Id == user.Id))
          {
               return;
          }
       //Code to respond to mention here
}