我正在嘗試實現一項功能,以在asp.Net和C#中的Twitter上發佈推文。我有訪問令牌,消費者密鑰,回調網址等。我有兩個按鈕「authenticicate」和「發送」來認證並分別發送推文。文字未在Twitter上發佈
我對所有這些都使用了Twitterizer2 dll。驗證和發送按鈕'點擊不會給出任何錯誤,但也不要在twitter上發佈任何內容。有什麼我需要添加或更改?請幫助。
protected void btnSendTwitterMsg_Click(object sender, EventArgs e)
{
OAuthTokens accessToken = new OAuthTokens();
accessToken.ConsumerKey = "XXXXXXXXXXXXXXXXXXXXXXXX";
accessToken.ConsumerSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
accessToken.AccessToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
accessToken.AccessTokenSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
TwitterStatus.Update(accessToken, "Hello World!!");
}
protected void btnAuthenticate_Click(object sender, EventArgs e)
{
var consumerKey = "XXXXXXXXXXXXXXXXXXXX";
var consumerSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
var callBackUrl = "my call back url";
if (Request.QueryString["oauth_token"] == null)
{
OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callBackUrl);
Response.Redirect("http://twitter.com/oauth/authorize?oauth_token=" + RequestToken.Token);
}
else
{
OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callBackUrl);
string oathToken = Request.QueryString["oauth_token"].ToString();
var accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, RequestToken.Token, RequestToken.VerificationString);
this.lblScreenName.Text = "Hello " + accessToken.ScreenName;
}
}
感謝 拉克什
PLZ格式代碼ptoperly。難以通過移動瀏覽器閱讀... – deostroll 2012-02-28 06:56:45
代碼格式化。感謝Pilgerstorfer Franz – 2012-02-28 08:21:42