【发布时间】:2023-04-04 16:13:01
【问题描述】:
我认为这个问题可能会被问一百万次,但我没有找到任何答案。
我正在尝试使用我的 Unity 项目访问 Google 日历,因此我使用的是 C#,但无法使用官方的 google 客户端库,因为它不受支持。
可悲的是,每次我尝试从服务器获取访问令牌时,我都会收到 404 或只是一个空响应。
我的代码:
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;
}
我已经使用以下方法调用了该方法:
Debug.Log(OAuth2.GetOAuthTokens(code, "authorization_code"));
Debug.Log 仅用于调试。
我看到很多人说我需要将我的 Uri 列入白名单,但我无法在凭据中找到该菜单点。
我现在搜索了大约 6 个小时。请帮忙!
【问题讨论】:
-
这也是我多年前做的一个非常简单的例子daimto.com/google-apis-auth-simple如果您有任何问题,请告诉我。我从未与 unity3d 合作过,但我很乐意帮助你解决这个问题。
-
@DalmTo 您如何使用官方文档中所述的不同端点?他们是否忘记更新文档或者您的文章是基于旧版本的?
-
@DalmTo 阅读您的文章并尝试过,但我的回复仍然是空的 + 我收到的回复代码为 0,这很奇怪
-
自从我写完之后端点已经改变了。使用发现文档中的那个
标签: c# unity3d oauth-2.0 google-oauth