OAuth访问令牌为空

OAuth访问令牌为空

本文介绍了Google OAuth访问令牌为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个问题可能被问了一百万遍,但是我没有找到任何答案.

i think this question might be asked a Million Times but i did not find any answers out there.

我正在尝试通过Unity项目访问Google日历,因此我使用的是C#,但是由于不支持而无法使用Google官方客户端库.

I'm trying to access Google Calendar with my Unity Project, so I'm Using C# but cant use the Official google client libraries as its not supported.

可悲的是,每次我尝试从服务器获取访问令牌时,都会得到404或空响应.

Sadly Every time i try to get the Access Token from the server i get either a 404 or just a empty response.

private static string tokenUrl = "https://oauth2.googleapis.com/";
public static string GetOAuthTokens(string auth_code, string grantType)
{
    RestClient rc = new RestClient(tokenUrl);
    RestRequest request = new RestRequest(Method.POST);
    request.Parameters.Clear();

    request.Resource = "token";
    request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
    request.AddParameter("auth_code", auth_code, ParameterType.RequestBody);
    request.AddParameter("client_id", client_id, ParameterType.RequestBody);
    request.AddParameter("secret", client_secret, ParameterType.RequestBody);
    request.AddParameter("grant_type", grantType, ParameterType.RequestBody);
    request.AddParameter("redirect_uri", "http://localhost:4444", ParameterType.RequestBody);
    return rc.Execute(request).Content;
}

我用以下方法调用了该方法:

And i've called that method with:

 Debug.Log(OAuth2.GetOAuthTokens(code, "authorization_code"));

Debug.Log仅用于调试.

我已经看到很多人说我需要将我的Uri列入白名单,但是我无法在凭据中找到该菜单项.

I've seen a lot of people saying i need to whitelist my Uri but i cant find that menu point in the credentials.

我现在搜索大约6个小时.请帮忙!

Im searching for about 6 hours now. Please Help!

推荐答案

我知道了:request.AddParameter("auth_code", auth_code, ParameterType.RequestBody);

必须是:request.AddParameter("code", auth_code, ParameterType.GetOrPost);

我想我必须重命名Parameter键以匹配文档

and i think i had to rename the Parameter keys to match the Documentation

这篇关于Google OAuth访问令牌为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 12:59