Twitter Streaming API C#

14,334

Solution 1

I have found a good sample code that uses streaming API, here Twitterizer.

Solution 2

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.

Solution 3

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.

Solution 4

Here is a sample which "Reads data from the Twitter Streaming API and adds it to MSMQ. A second process (included) reads from the queue, parses the json message, and updates a data store."

https://github.com/swhitley/TwitterStreamClient

You can change the above problem to generate an event when it updates the data store. In your program you can subscribe this event to do whatever you want.

If you are looking for OAuth based sample then please use "AuthPack" which Provides .NET oAuth for Twitter, Facebook, LinkedIn, and Google:

https://github.com/swhitley/AuthPack/tree/master/AuthPack

Share:
14,334
weikangchia
Author by

weikangchia

Updated on June 04, 2022

Comments

  • weikangchia
    weikangchia almost 2 years

    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.