推文:获取错误32无法验证您的身份

时间:2015-01-20 10:51:57

标签: c# windows-phone-8.1 twitter-oauth

我想发布一条推文,我正在从服务器获取访问令牌,使用我正在尝试推文但是收到错误"无法验证您的身份",无法找到我正在做的错误,这是我用于推文的代码。

私有异步任务TweetAsync (string access_token1 ="&#34 ;, string oauth_verifier1 ="")         {

        String TwitterUrl = "https://api.twitter.com/1.1/statuses/update.json";

        string timeStamp = GetTimeStamp();
        string nonce = GetNonce();

        String SigBaseStringParams = "oauth_consumer_key=" + TwitterClientID.Text;
        SigBaseStringParams += "&" + "oauth_nonce=" + nonce;
        SigBaseStringParams += "&" + "oauth_signature_method=HMAC-SHA1";
        SigBaseStringParams += "&" + "oauth_timestamp=" + timeStamp;
        SigBaseStringParams += "&" + "oauth_token=" + access_token1;
        SigBaseStringParams += "&" + "oauth_version=1.0";
        SigBaseStringParams += "&" + "status=twitteronwindowsphone";
        String SigBaseString = "POST&";
        SigBaseString += Uri.EscapeDataString(TwitterUrl) + "&" + Uri.EscapeDataString(SigBaseStringParams);

        String Signature = GetSignature(SigBaseString, TwitterClientSecret.Text);

        HttpStringContent httpContent = new HttpStringContent("oauth_verifier=" + oauth_verifier1, Windows.Storage.Streams.UnicodeEncoding.Utf8);
        httpContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
        string authorizationHeaderParams = "oauth_consumer_key=\"" + TwitterClientID.Text + "\", oauth_nonce=\"" + nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"" + Uri.EscapeDataString(Signature) + "\", oauth_timestamp=\"" + timeStamp + "\", oauth_token=\"" + Uri.EscapeDataString(access_token1) + "\", oauth_version=\"1.0\"";//, status=\"twitteronwindowsphone\"

        HttpClient httpClient = new HttpClient();

        httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("OAuth", authorizationHeaderParams);
        var httpResponseMessage = await httpClient.PostAsync(new Uri(TwitterUrl), httpContent);
        string response = await httpResponseMessage.Content.ReadAsStringAsync();

        string abc = response;
    }

0 个答案:

没有答案