1

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?

theGeekster
  • 6,081
  • 12
  • 35
  • 47

2 Answers2

0

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.

user2465083
  • 595
  • 3
  • 12
  • Yes, that's seems the only way so far. But because I have to add tracks in an already running stream so stopping/adding track/resuming stream is not likely a reliable solution as I am trying with Tweetinivi. So please let me know if you have better suggestion for this ? – theGeekster May 28 '14 at 09:13
  • I will try to have a look into it. But in any case with Tweetinvi or any other API you need to request the endpoint with your parameters. So there is no way to modify a stream while it is already running. You will always have to stop the StreamReader and then restart a StreamReader with the correct endpoint. – user2465083 May 28 '14 at 12:10
  • So I am not getting you wrong, Tweetinvi.Stream.TrackedStream.StartStream(endpoint_url_with_parameters) is my case. Where I have to provide updated endpoint url every time new track to be added? Okey, can you please give me a correct example of that endpoint_url following a user @username ? – theGeekster May 29 '14 at 09:46
0

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
}
alstonp
  • 700
  • 6
  • 25