1

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

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

私はこれをコンソールアプリとしてやっています。

4

1 に答える 1

7

私の英語で申し訳ありませんが、私はあなたを助けようとします!

まず、認証を作成する必要があります。1 つの方法は、自分の Twitter カウントのユーザーとパスワードを使用することです。

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"); 

このページhttp://dev.twitter.comで Twitter にアプリケーションを登録する必要がある別の方法があります。ここでは、Web の方向である名前を入力してアプリケーションを登録すると、ConsumerKey、ConsumerSecert が提供されます。また、アクセス トークンの生成をクリックすると、AccessToken と AccessTokenSecret も提供されます。[設定] に移動し、[読み取り、書き込み、ダイレクト メッセージへのアクセス] オプションを選択することを忘れないでください。次に AccessToken を生成します。コードでこれを使用すると、次のようになります。

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);
}

protected void SendTweet_Click(object sender, EventArgs e) { twitterCtx.UpdateStatus("My Test Tweet");
}

簡単!!それがどのように機能するかはわかりました!最初にボタンauthorizeTwitterButtonをクリックすると、Twitterアカウントの承認が開始され、新しいウィンドウが開いてTwitterのログインが表示され、アプリケーションを承認し、必要な資格情報を使用してTwitterがページにリダイレクトされるため、送信ボタンをクリックするとあなたは新しいツイートを投稿します!

また、begin および complete 承認メソッドを使用する必要がない別の方法もあります。ここでは、すべての資格情報を直接紹介します。例えば:

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/のドキュメントを参照してください 。私の答えが気に入ったら、クリックしてください!! ジャジャ

于 2012-08-16T17:43:07.490 に答える