2010-05-17 17 views

Respuesta

15

sólo tiene que utilizar este contenedor implementado para la API de Twitter:

https://github.com/danielcrenna/tweetsharp

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

    var response = twitter.Request(); 

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

There is even a DotNetRocks interview with the developers.

+1

Achilles, gracias por su respuesta! –

+2

Enlace roto http://tweetsharp.codeplex.com/ – jth41

+1

Parece que vive aquí ahora: https://github.com/Yortw/tweetmoasharp –

5

Sí, puede hacerlo sin una biblioteca de terceros. Vea mi IronPython sample publicado en el sitio IronPython Cookbook que le muestra exactamente cómo. Incluso si no lo hace el programa en IronPython, la parte principal del código que servirán para iniciar se repite a continuación y fácil de portar a 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) 

Básicamente, esto hace un HTTP POST a http://twitter.com/statuses/update.xml con una sola El campo HTML FORM llamado status y que contiene el texto de actualización de estado para la cuenta identificada por username (y password).

+5

Eso funciona bien hoy, pero dejará de funcionar cuando Twitter desactive la autenticación básica el próximo mes. –

+0

+1 para realmente comprender la pregunta (hacerlo con una API). –

6

he creado un tutorial de vídeo que muestra exactamente cómo configurar la aplicación en el interior gorjeo, instalar una biblioteca API usando Nuget, aceptar un token de acceso de un usuario y enviar en nombre de ese usuario:

vídeo: http://www.youtube.com/watch?v=TGEA1sgMMqU

Tutorial: http://www.markhagan.me/Samples/Grant-Access-And-Tweet-As-Twitter-User-ASPNet

En caso de que no quieren salir de esta página:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

using Twitterizer; 

namespace PostFansTwitter 
{ 
    public partial class twconnect : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      var oauth_consumer_key = "gjxG99ZA5jmJoB3FeXWJZA"; 
      var oauth_consumer_secret = "rsAAtEhVRrXUTNcwEecXqPyDHaOR4KjOuMkpb8g"; 

      if (Request["oauth_token"] == null) 
      { 
       OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
        oauth_consumer_key, 
        oauth_consumer_secret, 
        Request.Url.AbsoluteUri); 

       Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", 
        reqToken.Token)); 
      } 
      else 
      { 
       string requestToken = Request["oauth_token"].ToString(); 
       string pin = Request["oauth_verifier"].ToString(); 

       var tokens = OAuthUtility.GetAccessToken(
        oauth_consumer_key, 
        oauth_consumer_secret, 
        requestToken, 
        pin); 

       OAuthTokens accesstoken = new OAuthTokens() 
       { 
        AccessToken = tokens.Token, 
        AccessTokenSecret = tokens.TokenSecret, 
        ConsumerKey = oauth_consumer_key, 
        ConsumerSecret = oauth_consumer_secret 
       }; 

       TwitterResponse<TwitterStatus> response = TwitterStatus.Update(
        accesstoken, 
        "Testing!! It works (hopefully)."); 

       if (response.Result == RequestResult.Success) 
       { 
        Response.Write("we did it!"); 
       } 
       else 
       { 
        Response.Write("it's all bad."); 
       } 
      } 
     } 
    } 
}