[英]Windows phone 7: how to post tweet to twitter
目前,我正在從Windows Phone共享功能。
我的目的是從Windows Phone應用程序向Facebook和Twitter分享用戶的狀態。
我成功完成了Facebook共享,現在我試圖將狀態(僅120 Words tweet)共享給Twitter。
我使用this完成了Twitter帳戶的身份驗證。
當我嘗試使用此tweet按鈕單擊事件登錄到帳戶后,將tweet發布到twitter帳戶時,
private void btnPostTweet_Click(object sender, RoutedEventArgs e)
{
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = AppSettings.consumerKey,
ConsumerSecret = AppSettings.consumerKeySecret,
Token = this.accessToken,
TokenSecret = this.accessTokenSecret,
Version = "1.1"
};
var restClient = new RestClient
{
Authority = "https://api.twitter.com",
HasElevatedPermissions = true
};
var restRequest = new RestRequest
{
Credentials = credentials,
Path = "/1.1/statuses/update.json",
Method = WebMethod.Post
};
restRequest.AddParameter("status", Uri.EscapeDataString(txtTweetContent.Text));
restClient.BeginRequest(restRequest, new RestCallback(PostTweetRequestCallback));
}
在回調中
private void PostTweetRequestCallback(RestRequest request, RestResponse response, object obj)
{
string str = response.ToString();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(AppSettings.TWEET_POSTED_SUCCESSFULLY);
}
else if (response.StatusCode == HttpStatusCode.Forbidden)
{
MessageBox.Show(AppSettings.TWEET_POST_ERR_UPDATE_LIMIT);
}
else
{
MessageBox.Show(AppSettings.TWEET_POST_ERR_FAILED);
}
txtTweetContent.Text = "";
});
}
它給了我錯誤
"Bad Authentication data", Code="215"
我已經成功地將我的應用程序注冊到twitter開發人員帳戶,並在進行此調用之前已收到訪問令牌密鑰。
通過分析您的代碼,看來您必須在下面的代碼塊中進行更改:
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = AppSettings.consumerKey,
ConsumerSecret = AppSettings.consumerKeySecret,
Token = this.accessToken,
TokenSecret = this.accessTokenSecret,
Version = "1.1"
};
改變這個:
Version = "1.1" to Version="1.0"
現在,您的代碼將順利運行,祝您愉快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.