How do you stream only followed users

Feb 4, 2014 at 11:47 AM
I need to stream only those I follow. I cant quite understand how to approach this.. Is there a method for it (in underlying API) and if yes is it implemented in the TweetInvi?

Or shall I stream all tweets but then filter them by the author locally?
Coordinator
Feb 4, 2014 at 12:04 PM
Hi,

You need to use the UserStream. The goal of the userstream is to receive all the events related with an account.
When a follower post a tweet for example the information will be received by the userstream.

Tweetinvi 0.9.0.0
var userStream = Stream.CreateUserStream();
userStream.TweetCreatedByAnyoneButMe += (sender, args) =>
{
      Console.WriteLine("Tweet created by {0}", args.Tweet.Creator.Name);
};
userStream.StartStream();
Tweetinvi 0.8.3.23
IUserStream userStream = new UserStream();
us.TweetCreatedByAnyoneButMe += (sender, args) =>
{
       Console.WriteLine("Tweet created by {0}!", args.Value.Creator.Name);
};
userStream.StartStream(token);
Hope this helps.
Regards,
Linvi
Feb 4, 2014 at 12:19 PM
Gotcha thanks very much.. I almost done here :)
Feb 4, 2014 at 1:12 PM
Edited Feb 4, 2014 at 1:13 PM
Ok.. sorry.. it doesnt work as I thought it would be..

For example.. I have subscribed to @Reuters. And on my Twitter home page are tweets from @Reuters (that what I want).. But in the TweetInvi I am getting Reuters and others (I dont know what they are but the text mentioned @Reuters but is not the author... For example some guy called Fallapart The Clown writes some text started with "@Reuters" - seems people replying to the @Reuters tweets (I guess))..

My code:
        private IUserStream StartUserStream(IToken token)
        {
            IUserStream us = new UserStream();

            us.TweetCreatedByAnyone += (sender, args) =>
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    AddTweet(args.Value);
                }));
            };

            var a = new Action(() =>
            {
                us.StartStream(token);
            });

            a.BeginInvoke(null, null);

            return us;
        }
so basically I need to replicate Home page of my Twitter account.

Its almost there just one more push and I am good to go! :))

Thank you
Coordinator
Feb 4, 2014 at 1:27 PM
Hi,

You are pointing something that I did not considered when doing the UserStream.
I will have a look to this specific problem and get back to you probably tonight.

Regards,
Linvi
Feb 4, 2014 at 1:28 PM
You are the star! Thanks a ton!
Coordinator
Feb 5, 2014 at 12:41 AM
Hi there,

I have not yet implemented the solution but basically the logic is pretty simple.

The FriendIdsReceived event will send you the ids of all the users you are following.
When getting the tweets you can filter based on this list.
event EventHandler<GenericEventArgs<List<long>>> FriendIdsReceived;
I will implement this feature in Tweetinvi 0.9.0.0 but it seems you are using 0.8 consequently just store the list and filter based on it ;)

Regards,
Linvi
Feb 5, 2014 at 9:31 AM
will do.. not too big deal... I got 0.8 from the download page... shall I use code repository and compile 0.9 myself or how it works with this project?
Coordinator
Feb 5, 2014 at 9:44 AM
Hi,

Tweetinvi 0.9 is still not accessible through the MainPage Download button but you can access it by downloading the Source Code and compiling the Development project.

This is getting more and more stable and the release will happen between 2 to 4 weeks after 5 months of development :)
There are few differences but the goal of 0.9 is to simplify the development and the Examplinvi project will help you going through.

Download Tweetinvi 0.9

I will let you know when the feature is implemented.

Linvi
Marked as answer by linvi on 2/5/2014 at 2:42 PM
Feb 5, 2014 at 9:45 AM
cheers!
Coordinator
Feb 5, 2014 at 10:18 AM
Edited Feb 5, 2014 at 5:59 PM
This discussion has been copied to a work item. Click here to go to the work item.
Coordinator
Feb 5, 2014 at 10:42 PM
This is now implemented in Tweetinvi 0.9.0.0.
var ustream = Stream.CreateUserStream();
ustream.TweetCreatedByFriend += (sender, args) =>
{
    Console.WriteLine("Follower {0} posted : '{1}'", args.Tweet.Creator.Name, args.Tweet.Text);
};
ustream.StartStream();
Also for the information, TweetCreatedByAnyone will send tweet created by followers and tweets from users who reply to tweets of followers.

Regards,
Linvi
Marked as answer by linvi on 2/5/2014 at 2:42 PM
Feb 5, 2014 at 11:17 PM
Very nice. Thank you.. Will try tomorrow morning.