Pinterest API错误405 POST请求

时间:2017-04-12 02:14:56

标签: c# oauth uwp pinterest http-status-code-405

我在我正在处理的UWP应用中发送Pinterest的POST请求时出现问题。我已经拥有了以前的WebAuthenticationBroker函数的访问代码。我尝试使用带有UseHttpPost选项的WebAuthenticationBroker和验证异步的选项,但是,由于我提供了if函数,它返回ERROR。我刚收到一条消息":" 405:方法不允许"和"键入" :" http"。我看了一遍,我甚至尝试过使用HttpClient和PostAsync(),但是我无法获得它来获取访问令牌。对我做错了什么建议?

private void OutputToken(string TokenUri)
    {
        int tokenString = TokenUri.IndexOf('=');
        string TheTokenUri = TokenUri.Substring(tokenString + 54);
        PinterestReturnedTokenText.Text = TheTokenUri;
        outputToken = TheTokenUri;
    }

    private async void auth()
    {
        try
        {
            string CallbackUrl = "https://localhost/";
            string PinterestUrl = "https://api.pinterest.com/v1/oauth/token?grant_type=authorization_code&client_id=" + PinterestClientID + "&client_secret=" + PinterestClientSecret + "&code=" + outputCode;

            Uri StartUri = new Uri(PinterestUrl);
            Uri EndUri = new Uri(CallbackUrl);

            WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseHttpPost, StartUri, EndUri);
            if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
            {
                OutputToken(WebAuthenticationResult.ResponseData.ToString());
                await GetPinterestNameAsync(WebAuthenticationResult.ResponseData.ToString());
            }
            else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
            {
                OutputToken("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString());
            }
            else
            {
                OutputToken("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString());
            }
        }
        catch (Exception Error)
        {
            PinterestReturnedTokenText.Text = "ERROR";
        }
    }

0 个答案:

没有答案
相关问题