views:

1559

answers:

6

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

+3  A: 

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.

John Kraft
It was my mistake - i didn't actually run this script because I placed it after Application.Run. But you have good point with catch. So I've market it as a tip.
tomaszs
+3  A: 

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/

Daniel A. White
A: 

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.

Neil Barnwell
As I wrote in my question - no external library
tomaszs
I said to look at it for inspiration - then write your own. Geez.
Neil Barnwell
Ah, ok. I apologise.
tomaszs
+2  A: 

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();
  }
}
bendewey
A: 

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.

Anjisan
A: 

Hi All

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

Kieran