无效的grant_type YouTube api

时间:2016-04-10 12:08:35

标签: c# asp.net asp.net-mvc youtube-api

我正在尝试交换访问令牌的授权码。我正在使用ASP.NET中的HttpClient发布帖子请求:

var clientId = "clientid";
var redirectUri = "http://localhost:65148/Welcome";
var clientSecret = "clientsecret";

if (code != null)
{
    //Lets exchange the code for a access token
    using (var client = new HttpClient())
    {
        var values = new Dictionary<string, string>
        {
            { "code", code },
            { "client_id", clientId },
            { "client_secret", clientSecret },
            { "redirect_uri", redirectUri },
            { "grant_type", code }
        };


        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
        var content = new FormUrlEncodedContent(values);
        var response = await client.PostAsync("https://accounts.google.com/o/oauth2/token", content);
        var responseString = await response.Content.ReadAsStringAsync();
        var value = Json(new { data = responseString });
        return value;
    }

}

但是当我运行它时,我收到一条错误消息:

{
    "error" : "invalid_request",
    "error_description" : "Invalid grant_type:4/AlxtyFqHeOiTC32THJgipkUWtHBO27GqFfgOoOCG9wE"
}

我不知道为什么我会这样做。

0 个答案:

没有答案