How to update Twitter status from c#?

2019-03-22 07:44发布

I would like to update status on Twitter without using external libraries nor dll-s. I've found for example this solution:

http://www.dreamincode.net/code/snippet2556.htm

But it does not work and does not give any error.

Could you please tell me how to update status programmatically from c#?

When I catch error I get:

500 Internal Server Error

6条回答
相关推荐>>
2楼-- · 2019-03-22 08:15

There is a nice WCF version of the Twitter API on CodePlex called Vertigo

Also, the WCF REST Starter Kit has some really nice demos, look at the Videos Section

Here is a sample of how this would be done using the Starter Kit

public void PostTweet(string username, string password, string tweet)
{
  using (var client = new HttpClient())
  {
      System.Net.ServicePointManager.Expect100Continue = false;

      client.TransportSettings.Credentials =
          new NetworkCredential(username, password);

      var form = new HttpUrlEncodedForm();
      form.Add("status", tweet);

      client.Post("http://twitter.com/statuses/update.xml", form.CreateHttpContent())
          .EnsureStatusIsSuccessful();
  }
}
查看更多
欢心
3楼-- · 2019-03-22 08:15

Look at the Yedda Twitter library to get some inspiration for the concepts and classes required, then write your own. Essentially you're just mimiking HTTP gets/posts and doing things with the XML that you send/receive.

查看更多
太酷不给撩
4楼-- · 2019-03-22 08:18

Two thoughts on this Dream-in-Code snippet,

http://www.dreamincode.net/code/snippet2556.htm

First, I would put the Stream posting in a using block as in,

//send the request

using (Stream post = request.GetRequestStream()) { post.Write(byteData, 0, byteData.Length); }

Second, I see that one of the method parameters is,

string tweet

Since Twitter can only do a posting that is 140 characters or less, you should make sure that the incoming tweet string is likewise 140 characters or less. Ideally, you should deal with that before it hits this method.

查看更多
成全新的幸福
5楼-- · 2019-03-22 08:20

It might not give any errors because the catch block is 'eating' the exception. Try getting rid of the try/catch (for testing purposes only) or do something in the catch to notify you of any errors.

查看更多
唯我独甜
6楼-- · 2019-03-22 08:25

Here is a really good post on how to consume twitter services using c# ... It goes into the new Microsoft.Http library you can download it here

http://msdn.microsoft.com/en-us/netframework/cc950529.aspx

Watch the video and type =)

http ://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Consuming-REST-services-with-HttpClient/

Happy coding

查看更多
劫难
7楼-- · 2019-03-22 08:27

There is a simple http post method that you can use. Take a look here:

http://apiwiki.twitter.com/REST-API-Documentation#TheEasiestWaytoPlayAroundwiththeTwitterAPI

Edit Twitter will be moving to an oAuth method too. http://blog.stevienova.com/2008/04/19/oauth-getting-started-with-oauth-in-c-net/

查看更多
登录 后发表回答