当从已部署公司的项目调用 google 脚本 Web 应用程序 url 时得到 java.io.IOException:服务器返回 HTTP 响应代码:URL 的 403:

When call google script web app url from deployed company's project get java.io.IOException: Server returned HTTP response code: 403 for URL:

我用我的个人 google 帐户在 google 脚本中创建了一个项目。我将其部署为网络应用程序,并授予任何人甚至匿名访问权限,并且可以执行该应用程序].我在我为公司工作的项目中使用了已部署的 google 脚本网络应用程序 url。当我从本地主机调用 url 时,我从脚本中得到了结果。在我们部署调用 google 脚本 Web 应用程序的项目后,我们将代理配置添加到对 google 脚本的调用,因为该项目在 vpn 下运行,现在我无法再访问该脚本- 我收到以下错误:java.io.IOException:服务器返回 HTTP 响应代码:URL 的 403:https://script.googleusercontent.com/macros/echo?user_content_key.

我已经搜索过类似的问题,但老实说无法弄清楚问题出在哪里以及我必须做什么。我想我必须以某种方式将我们公司 project/domain 与此 google 脚本应用程序绑定,对吗?或者问题出在其他地方?

任何建议将不胜感激。

您可能需要设置 Cloud Platform Project

问题

The error 403, PERMISSION_DENIED: The caller does not have permission indicates that the Cloud Platform project used to authorize the request is not the same as the one used by the script.

由此article

在你的情况下,这可能意味着因为你是从未知服务器调用的,所以 Google 没有授权它。

可能的解决方案

  1. 转到https://console.cloud.google.com/
  2. 创建一个new project并记下项目编号。
  3. 启用 Apps Script API.
  4. 设置一个OAuth consent screen.

Applications that access Google APIs from a server (often using languages and frameworks like Node.js, Java, .NET, and Python) must specify authorized redirect URIs. The redirect URIs are the endpoints of your application server to which the OAuth 2.0 server can send responses.

  1. 从脚本更改 Apps 脚本默认项目:

  1. 确保范围在您的清单中正确配置。
  2. 保存新版本并重新部署。

您可能需要创建一个新的 Apps 脚本,复制您的代码,link它到云项目然后部署


参考资料