tags:

views:

214

answers:

4

My client would like me to use .NET to post to Twitter, and suggests that I use C#.

Q: How do I post "Hello World" to twitter using C#?

This post mentions a library called twitterizer. Isn't there a native way to do it without using a 3rd party library? (Maybe not since authentication is one of the requirements).

+1  A: 

I'd suggest reading up on the documentation on http://developer.twitter.com/start. It has all the information you will need.

Tejs
+1  A: 

Twitter has its own API to do that

Midhat
+8  A: 

Just use this implemented wrapper for the Twitter API:

http://tweetsharp.codeplex.com/

    var twitter = FluentTwitter.CreateRequest()   
    .AuthenticateAs("USERNAME", "PASSWORD")   
    .Statuses().Update("Hello World!")   
    .AsJson();   

    var response = twitter.Request();  

From: http://code-inside.de/blog-in/2009/04/23/howto-tweet-with-c/

There is even a DotNetRocks interview with the developers.

Achilles
Accepting my answer would be...well...awesome :-D
Achilles
Achilles, thank you for your answer!
cf_PhillipSenn
+2  A: 

Yes, you can do it without any third-party library. See my IronPython sample posted on the IronPython Cookbook site that shows you exactly how. Even if you don't program in IronPython, the main part of the code that should get you started is repeated below and easy to port to C#:

ServicePointManager.Expect100Continue = False 
wc = WebClient(Credentials = NetworkCredential(username, password))
wc.Headers.Add('X-Twitter-Client', 'Pweeter')
form = NameValueCollection()
form.Add('status', status)
wc.UploadValues('http://twitter.com/statuses/update.xml', form)

Basically, this does an HTTP POST to http://twitter.com/statuses/update.xml with a single HTML FORM field called status and which contains the status update text for the account identified by username (and password).

Atif Aziz
That works fine today, but will stop working when Twitter turns off basic auth next month.
Jason Diller
+1 for actually comprehending the question (doing it with an API).
Charles