已部署的 Google App Script API 作为 Web App 无法从另一个 Google App Script 中使用

问题描述 投票:0回答:1

我创建了一个 Google 工作表(假设名称为 sheet1)并添加了一个从该工作表中检索数据的谷歌应用程序脚本(假设名称为 script1)。然后我将 google app 脚本部署为 web API,任何拥有 google 帐户的人都可以调用它

具有特权的已部署 Web 应用程序

1

然后,我与另一个人(假设名称 person2)共享了这个网络应用程序链接。 person2 可以直接从浏览器调用网络应用程序并返回数据。但如果 person2 从另一个谷歌应用程序脚本(假设名称 script2)调用此 API,它会返回一条未经授权的消息。

另外,我创建了另一个脚本(假设名称为script3)(我是所有者)并在script2中使用了相同的代码,脚本成功返回了数据。

如果我将 script3 的特权授予 person2,并且 person2 执行它,脚本将返回一条未经授权的消息。但是如果我把 sheet1 的权限给了 person2。是人 2 执行的脚本,它成功返回数据。

这是我脚本的代码

function callWebService(url) {
  try {
    var token = ScriptApp.getOAuthToken();
    var headers = { Authorization: 'Bearer ' + token };

    let config = {
      method: "get",
      headers: headers,
      'muteHttpExceptions': true
    };

    var responseStr = UrlFetchApp.fetch(url, config);
    response = JSON.parse(responseStr);

    if (response.success == true) {
      return response;
    } else {
      console.error("ERROR call web service URL: " + url + ";   with response: " + responseStr);
    }
  } catch (e) {
    console.error("ERROR call web service URL: " + url + ";   with error: " + e);
  }
}

我想让 person2 在不给他 sheet1 权限的情况下调用 web API。

怎么做。

非常感谢您提供的任何帮助。

google-apps-script google-sheets google-sheets-api google-apps
1个回答
0
投票

其实我也不知道为什么会出现这个问题

我创建了另一个工作表并在部署中执行了相同的步骤。并使用相同的代码适当地调用公开的 Web 服务。

© www.soinside.com 2019 - 2024. All rights reserved.