2012-03-04 20 views
1

私は申し訳ありませんが、明白だが、私は答えを見つけることができません。私はステータスを投稿したい。私が見つけることができるのは、これらの2つの行だけです。私はログインする方法を理解できません。私はそのユーザー/パスワード、またはAPIキーを使用している場合は気にしません。twitterにlinqでログインするにはどうすればいいですか?

var twitterCtx = new TwitterContext(); 
var tweet = twitterCtx.UpdateStatus(@"test text"); 

これはコンソールアプリケーションとして実行しています。

+0

多くの苦痛と様々な.NET twitterラッパーの後、私はnugetパッケージマネージャーhttp://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970cを取得し、そこからtweetsharpをインストールしました。 –

+0

Linq-to-twitter?コードには140文字しか使用できません。代わりに、TwitterContext(UsernamePasswordAuthorization)コンストラクタを試してみてください。 –

+0

@ HansPassant:私はそれに関する文書は見ません。しかし、私はtweetsharpとmono/linuxを使ってこれを手に入れました。 –

答えて

7

私の英語は申し訳ありませんが、お手伝いをします!

まず、認証を作成する必要があります。ユーザーとパスワードは、自分のtwitterカウントのものです。あなたが名前を入れaplicattionを登録し、ここで、このページhttp://dev.twitter.comうtwitterでaplicationを登録する必要があり、別の方法が、あり

UsernamePasswordAuthorization cxauthentication = new UsernamePasswordAuthorization(); 
ctxauthenticatin.UserName = userName; // Put in your Twitter Account 
ctxauthenticatin.Password = password; // and password 
ctxauthenticatin.AllowUIPrompt = false; 
ctxauthenticatin.SignOn(); 

var ctxTwitterContext = new TwitterContext(ctxauthentication); 
ctxTwitterContext.UpdateStatus("test text"); 

、ウェブのdireccionは、その後、彼らはあなたのConsumerKey、ConsumerSecertを与え、あなたがAccess Tokenを生成するのを止めれば、彼らはあなたにAccessTokenとAccessTokenSecretを与えます。 Remenber設定に移動し、ダイレクトメッセージの読み取り、書き込み、およびアクセスオプションを選択します。 AccessTokenを生成します。あなたのコードでこれで[OK]を、あなたはこのような何かを:

public partial class _Default : System.Web.UI.Page 
{ 
private WebAuthorizer auth; 
private TwitterContext twitterCtx; 

protected void Page_Load(object sender, EventArgs e) 
{ 
    IOAuthCredentials credentials = new SessionStateCredentials(); 

    if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null) 
    { 
     credentials.ConsumerKey = "Here put your ConsumerKey"; 
     credentials.ConsumerSecret = "Here put your ConsumerSecret" 
    } 

    auth = new WebAuthorizer 
    { 
     Credentials = credentials, 
     PerformRedirect = authUrl => Response.Redirect(authUrl) 
    }; 
     if (!Page.IsPostBack) 
    { 
     auth.CompleteAuthorization(Request.Url); 
    } 
    twitterCtx = new TwitterContext(auth); 
} 
protected void authorizeTwitterButton_Click(object sender, EventArgs e) 
{ 
    auth.BeginAuthorization(Request.Url); 
} 

保護無効SendTweet_Click(オブジェクト送信者、EventArgsの電子) { twitterCtx.UpdateStatus( "私のテストツイート");
}

Easy !!それはどのように動作しますか?最初にauthorizeTwitterButtonというボタンをクリックすると、Twitterアカウントの権限が開始され、新しいウィンドウが開き、アプリケーションを承認したtwitterのログインが表示され、twitterは認証ボタンをクリックしてページにリダイレクトしますあなたは新しいつぶやきを投稿します!

また、開始方法と完了方法を使用する必要がない別の方法もあります。ここでは、すべての資格情報を直接紹介します。例えば、

var auth = new SingleUserAuthorizer 
{ 
      Credentials = new InMemoryCredentials 
      { 
       ConsumerKey = "your ConsumerKey", 
       ConsumerSecret = "Your consumerSecret", 
       OAuthToken = "your AccessToken", 
       AccessToken = "your AccessTokenSecret"] 
      } 
     }; 
var ctxTwitterContext = new TwitterContext(auth); 
ctxTwitterContext.UpdateStatus("test text"); 

Ok!私のアンカーがあなたを助けることを願っています!詳細については、http://linqtotwitter.codeplex.com/ の文書をご覧ください。私のアンサーが好きなら、ただクリックをしてください! jaja

+0

これは古い質問であり、コメントで私はすでに何か働いていると言いました。しかし+1とにかく –

+0

私はtweetsharpが好きです。 https://github.com/danielcrenna/tweetsharp#authenticating-a-client-application-ie-desktop。私がアプリのコンシューマーキー/シークレットを入れた後、小さなコードはユーザーが自分のアカウントを承認するための努力をしません。 –

関連する問題