Post “Hello World” to twitter from .NET application

后端 未结 6 1322
耶瑟儿~
耶瑟儿~ 2020-12-14 04:30

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

6条回答
  •  臣服心动
    2020-12-14 05:27

    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).

提交回复
热议问题