【问题标题】:Google Sheet error:"Exception: We're sorry, a server error occurred. Please wait a bit and try again"Google 表格错误:“异常:很抱歉,发生服务器错误。请稍候,然后重试”
【发布时间】:2021-01-21 02:42:35
【问题描述】:

以下代码行在 ScriptA 中有效,但在 ScriptB 中无效:

var folder = DriveApp.getFolderById(folderId);

两个脚本文件中的 oAuth 相同 appsscript.json:

...
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets.readonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.external_request"
],
...

我错过了什么?

【问题讨论】:

  • 您使用的脚本是否部署为附加组件? @EdmundTo
  • 这能回答你的问题吗? stackoverflow.com/questions/64079595/…
  • 这可以通过访问菜单Resources 批准脚本文件中的Google Drive APIDrive API 来解决 --> Advanced Google Services...,然后启用Drive API,然后在底部单击指向Google Cloud Platform API Dashboard 的链接并启用Google Drive APIDrive API。正如@TheMaster 指出的那样,复制到新电子表格的方法有效,但如果您想保留相同的 FileId stackoverflow.com/questions/64079595/…,则并不理想
  • @EdmundTo 考虑将其添加为答案
  • 我不允许添加答案,不知道为什么。如果可以,也许您可​​以添加它,我可以接受吗? @TheMaster

标签: google-apps-script google-sheets server-error


【解决方案1】:

我遇到了类似的问题(尽管使用 DriveApp.getFiles()DriveApp.searchFiles() 函数),我看到“出现问题 - 请重新加载页面以重试”错误。 经过一个多小时的调查,我将其范围缩小到与有问题的 AppScript 相关的 Google Cloud Project (GCP)。

如果您为脚本选择了 GCP 项目,则该项目必须启用相应的 GCP API。对于DriveApp SDK/库,我必须启用Google Drive API (see docs),然后为我解决了这个问题。

如果脚本仍在使用默认项目,我发现不需要额外的操作;这可能意味着底层 GCP 项目已经为每个受支持的 AppScript 集成启用了所有需要的 API。

有趣的是,Advanced services requirements 下提到了这一点,但不清楚为什么 DriveApp 功能也会受到影响,因为它们没有列在“高级服务”下(毕竟我们没有使用 Drive API)。我创建了a bug ticket in google's issue tracker 来尝试了解这一点。

【讨论】:

    【解决方案2】:

    这可以通过访问菜单Resources>Advanced Google Services...激活脚本文件中的Google Drive API Advanced Services来解决,然后启用Drive API,然后在底部单击指向 Google Cloud Platform API 仪表板的链接并在此处启用 Drive API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-02
      • 2017-05-02
      • 1970-01-01
      • 2020-12-07
      • 2014-05-21
      • 1970-01-01
      相关资源
      最近更新 更多