Error 403 “forbidden” 在 Unity Web 应用程序上抛出。

huangapple go评论55阅读模式
英文:

Error 403 "forbidden" being thrown on unity web application

问题

最近(过去一周内),我们的Unity WebGL应用(Unity版本2019.4.16f1)无法使用Google Drive API读取文件。当我检查Web控制台时,我看到以下错误消息:

UnityGoogleDrive: HTTP/1.1 403 Forbidden
Google Drive API错误描述:代码'403' 消息:'请求缺少有效的API密钥。'
域:'全局' 原因:'禁止' 消息:'请求缺少有效的API密钥。' 位置类型:'' 位置:''
(文件名:./Runtime/Export/Debug/Debug.bindings.h 行:35)

该应用程序已经运行了4个月,之前没有问题。我们目前已经设置了OAuth 2.0客户端ID,但没有API密钥,因为以前不需要。我们在Unity中用于访问Google Drive的插件(https://github.com/Elringus/UnityGoogleDrive)似乎没有明显的设置来添加API密钥,除了OAuth ID。

当直接在Unity中运行应用程序(使用localhost)时,没有错误,可以访问文件。

我已经尝试禁用并重新启用云控制台中的API。这带来了不同的结果。重新启用Google Drive API后,Web应用程序的初始请求成功,没有任何错误。但所有后续请求都失败,出现相同的错误。

根据缺失的值,我认为问题可能是我们需要为Google项目分配一个有效的计费计划,但这也没有解决问题。

我已经尝试生成API密钥,但我不确定在哪里传递它以解决问题(如果这甚至是问题的原因)。

英文:

Recently (within past week) our unity webgl (Unity v2019.4.16f1) application has been unable to read files using the google drive API. When I check the web console I see the following error:

> UnityGoogleDrive: HTTP/1.1 403 Forbidden
> Google Drive API Error Description: Code '403' Message: 'The request is missing a valid API key.'
> Domain: 'global' Reason: 'forbidden' Message: 'The request is missing a valid API key.' LocationType: '' Location: ''
> (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

The application has been in place for 4 months without issue until now.
We currently have an OAuth 2.0 client ID setup, but no API key as we haven't needed it before. The plugin we are using for google drive access in Unity (https://github.com/Elringus/UnityGoogleDrive) does not have any obvious settings for adding an API key in addition to the OAuth ID.

When running the application directly in Unity (which uses localhost) there are no errors and files can be accessed.

I have tried disabling and re-enabling the API in the cloud console. This has given mixed results. The initial request on the web application after re-enabling the Google Drive API succeeds without any errors. All subsequent requests fail with the same error.

Based on the missing values I thought the issue might be that we needed a valid billing plan assigned to the google project but that has not resolved the issue either.

I have tried generating an API key but I am not sure where I need to pass it in order to resolve the issue (if that is even the cause of the issue).

答案1

得分: 0

报告的错误是一个误导。真正的问题是我们的请求没有触发与Google的身份验证。我们的Unity开发环境缓存了一个身份验证令牌,这就是为什么开发环境能够正常工作,而生产应用程序失败的原因。

我们通过在任何其他操作之前向GoogleDriveAbout API发送一个请求来解决了这个问题,这似乎能够可靠地触发重新身份验证。一旦身份验证成功,一切都按预期工作。

英文:

The error reported was a red herring. The real issue was that our request was not triggering authentication with Google. Our Unity dev environment had cached an authentication token which is why the dev environment functioned but the production app failed.

We resolved the issue by sending a request to the GoogleDriveAbout API before anything else, which seems to reliably trigger reauthentication. Once authenticated everything works as expected.

huangapple
  • 本文由 发表于 2023年2月7日 00:58:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364334.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定