Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Streaming API C#

Hi does anyone know how to use the streaming API for C#? Therefore, whenever there is a new tweet in my account, it will be reflected in my program.

like image 389
weikangchia Avatar asked Jun 08 '12 06:06

weikangchia


2 Answers

So far the only reliable wrapper I've found for this in .Net land is TweetInvi. Try to ignore that the web site looks like it was designed by a hyperactive 10-year old (thanks MS 'metro' team), the actual library is very well designed and rock solid.

Assuming of course you have the relevant access tokens (if not see http://dev.twitter.com), an example of how easy it is to have up and running:

TwitterCredentials.SetCredentials(userToken,userTokenPrivate,apiKey,apiKeyPrivate);
_userStream = Stream.CreateUserStream();
_userStream.TweetCreatedByFriend += (sender,args) => Console.WriteLine(args.Tweet.Text);
_userStream.Start();

This will write the body of tweets to your console output, and it updates even faster than leaving the actual Twitter web site open. There are other events exposed for when a tweet is favourited, retweeted, when you have a new follower etc.

I can vouch for this library as being reliable - I am using it for my CovertTweeter project and have had absolutely no issues with it. In fact accessing the streaming API through TweetInvi has been even easier than the many brick walls I was left hitting when using REST wrappers like Linq2Twitter and TweetSharp.

like image 182
nathanchere Avatar answered Oct 18 '22 10:10

nathanchere


Have a look at this post:

Streaming with New .NET HttpClient and HttpCompletionOption.ResponseHeadersRead

You don't have the complete implementation there but you will get the idea.

like image 38
tugberk Avatar answered Oct 18 '22 12:10

tugberk