Windows Phone 7的:如何发布鸣叫叽叽喳喳 [英] Windows phone 7: how to post tweet to twitter

查看:132
本文介绍了Windows Phone 7的:如何发布鸣叫叽叽喳喳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在从Windows Phone的共享功能。

Currently i am working on sharing functionality from windows phone.

我的目的是从我的Windows Phone应用程序共享用户在Facebook和Twitter的状态。

My purpose is to share the status of the user to Facebook and the Twitter from my windows phone App.

我完成了Facebook的成功分享,现在即时通讯试图共享的状态(120字仅鸣叫)到Twitter。

I completed the Facebook sharing successfully and now i m trying to share the status (120 Words tweet only) to twitter.

我完成了使用使用Twitter帐户验证。

I completed the Authentication with Twitter account using this.

当我尝试鸣叫张贴在使用这条推按钮单击事件的帐户,

When i try to post the tweet to the twitter account after am logged in to the account using this tweet button click event,

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



它给了我误差

it gives me error as

"Bad Authentication data", Code="215"

我已经成功注册我给Twitter开发人员帐户和应用在进行此调用之前收到的访问令牌密钥。

I've successfully registered my Application to twitter developer account and Received the Access Token keys before making this call.

推荐答案

从分析你的代码,它似乎你在下面的代码块来改变:

From analyzing your code its seems you have to change at below code block :

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



更改此:

Change this :

 Version = "1.1" to Version="1.0"

现在您的代码将工程进展顺利,享受这一天。

Now your code will works smoothly, enjoy the day.

这篇关于Windows Phone 7的:如何发布鸣叫叽叽喳喳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆