google-apps-script - Google Apps 脚本中的 "Allow this application to run when you are not present"

标签 google-apps-script

为什么我的附加组件要求此权限?尝试查看文档并找不到任何内容。

the permission request I'm getting

据我所知,当用户不存在时,我的应用程序不会运行! (它要求用户在 Google Sheets 中选择一个范围,在自定义 UI 中按下一个按钮,然后调用一个外部 API)。对于我应该寻找什么来找到触发此类权限请求的违规代码或配置,是否有任何提示?

最佳答案

这个答案怎么样?

1.快速确认

Allow this application to run when you are not present



当显示上述授权信息时,表示使用了https://www.googleapis.com/auth/script.scriptapp范围的方法。项目中使用。您可以在文件 -> 项目属性 -> 范围中查看项目中的范围。需要这种范围的方法尤其在ScriptApp .当getProjectTriggers() , getUserTriggers() , deleteTrigger() , newTrigger()在项目中使用时,会自动检测此类范围。
如果您已经注意到在您的项目中使用了此类方法,那么本节可能是一个答案。

2. 调查

如果你已经注意到这样的方法是 不是 在您的项目中使用,请检查此部分。

保存 GAS 项目时,自动检测项目中使用的范围。这种自动检测也适用于注释掉的方法。此外,即使将每个单词分开,也会检测到该单词,因为自动检测对特殊单词起作用,如下所示。
ScriptApp.getOAuthToken()

// .... do something

// newTrigger  <--- this is put as a comment

当上述脚本在项目中时,自动检测说https://www.googleapis.com/auth/script.scriptapp是必须的。但在这个样本中,ScriptApp.getOAuthToken()不需要 https://www.googleapis.com/auth/script.scriptapp .

如果您想确认是否需要使用此类范围的授权才能运行您的脚本,您可以使用“ list ”来完成。最近,“ list ”被添加到 GAS 项目中。使用“ list ”,可以停止范围的自动检测。通过这个,你可以知道检测到的范围是否是项目实际需要的。为了确认这一点,请执行以下流程。
  • 在脚本编辑器上。
  • 文件 -> 项目属性 -> 范围
  • 复制当前范围。
  • 查看 -> 显示 list 文件
  • appsscript.json出现。
  • 请将复制的范围添加到 appsscript.json如下。

  • 默认appsscript.json
    {
      "timeZone": "### your timezone ###",
      "dependencies": {
      },
      "exceptionLogging": "STACKDRIVER"
    }
    

    为此,请按如下方式添加复制的范围。请保存这个。
    {
      "timeZone": "### your timezone ###",
      "dependencies": {
      },
      "exceptionLogging": "STACKDRIVER",
      "oauthScopes": [
        "https://www.googleapis.com/auth/script.scriptapp",
        "scope2",
        "scope3",
        ...
      ]
    }
    

    添加后oauthScopes , 首先,请确认您的脚本是否正常工作。然后,删除 https://www.googleapis.com/auth/script.scriptapp来自 oauthScopes ,然后再次运行。此时如果有错误,说明错误的行使用了https://www.googleapis.com/auth/script.scriptapp的范围。 .

    笔记 :
  • 还有一种可能是授权Allow this application to run when you are not presenthttps://www.googleapis.com/auth/script.scriptapp 无关.
  • 当您看到项目中的范围时,如果 https://www.googleapis.com/auth/script.scriptapp不包括,将范围添加到 appsscript.json 后,请通过一一删除范围来确认错误行。

  • 引用 :
  • ScriptApp
  • Manifests

  • 如果这对你没有用,我很抱歉。

    关于google-apps-script - Google Apps 脚本中的 "Allow this application to run when you are not present",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48179449/

    相关文章:

    javascript - 在 Google Sheet 脚本中调用服务器端函数后关闭 HTML 页面

    javascript - 过滤具有 2 天前时间戳的对象

    google-apps-script - 通过 DriveApp.getFileById 从 Google Drive 到 Google Slides 的图像

    json - 如何从 JSON 响应中提取对象属性

    javascript - 如何将重复的单元格与谷歌应用程序脚本合并在一起?

    gmail - Gmail+Google Apps 脚本的最大发送速率和每日配额?

    google-apps-script - 使用 Google Apps 脚本从 Google Drive 中删除文件

    google-apps-script - 在事件发生时将 "automatically"电子表格作为 .xlsx 下载到本地计算机

    google-apps-script - 谷歌应用脚​​本: Export all Google contacts as CSV

    javascript - Google Apps 脚本 replaceText() 不适用于撇号 "'“