“当您不在时允许该应用程序运行"在Google Apps脚本中 [英] "Allow this application to run when you are not present" in Google Apps Script

查看:82
本文介绍了“当您不在时允许该应用程序运行"在Google Apps脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的加载项要求获得此许可?试图浏览文档,却找不到任何东西.

Why is my add-on asking for this permission? Tried looking through the docs and couldn't find anything.

据我所知,当用户不在时我的应用程序无法运行! (它要求用户在Google表格中选择一个范围,在自定义用户界面中按一个按钮,然后调用外部API).对于寻找引发此类许可请求的违规代码或配置,我应该寻找什么提示?

As far as I know, my application doesn't run when the user isn't present! (It requires the user to select a range in Google Sheets, press a button in custom UI, and call an external API). Are there any tips for what I should look for to find the offending code or configuration that's triggering such a permission request?

推荐答案

此答案如何?

在您不在家时允许该应用程序运行

Allow this application to run when you are not present

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

When above authorization message is displayed, it means that the methods which use the scope of https://www.googleapis.com/auth/script.scriptapp is used in the project. You can see the scope in the project at File -> Project properties -> Scopes. The methods which need such scope are in especially ScriptApp. When getProjectTriggers(), getUserTriggers(), deleteTrigger(), newTrigger() are used in the project, such scope is automatically detected. If you have already noticed that such methods are used in your project, this section might be an answer.

如果您已经注意到项目中未使用这种方法,请检查此部分.

If you have already noticed that such methods are NOT used in your project, please check this section.

保存GAS项目时,将通过自动检测来检测项目中使用的范围.这种自动检测也适用于注释掉的方法.此外,即使每个单词分开,也可以检测到该单词,因为自动检测适用于特殊单词,如下所示.

When the GAS project is saved, the scopes which are used in the project are detected by the automatic detection. This automatic detection also works for commented out methods. Furthermore, even when each word is separated, the word is detected, because the automatic detection works for the special words, as follows.

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.

When above script is in the project, the automatic detection says that https://www.googleapis.com/auth/script.scriptapp is required. But in this sample, ScriptApp.getOAuthToken() doesn't require https://www.googleapis.com/auth/script.scriptapp.

如果要确认是否需要使用这种范围的授权来运行脚本,则可以使用清单"来进行.最近,清单"已添加到GAS项目中.使用清单",可以停止自动检测范围.这样,您可以知道检测到的范围是否实际是项目所必需的.为了确认这一点,请执行以下流程.

If you want to confirm whether the authorization which uses such scope is required to run your script, you can do it using "Manifests". Recently, "Manifests" was added to GAS project. Using "Manifests", the automatic detection of scopes can be stopped. By this, you can know whether the detected scopes are actually required to the project. In order to confirm this, please do the following flow.

  1. 在脚本编辑器上.
  2. 文件->项目属性->范围
  3. 复制当前作用域.
  4. 查看->显示清单文件
    • appsscript.json出现.
  1. On the script editor.
  2. File -> Project properties -> Scopes
  3. Copy current scopes.
  4. View -> Show Manifest file
    • appsscript.json appears.

默认appsscript.json

{
  "timeZone": "### your timezone ###",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER"
}

为此,请添加复制的范围,如下所示.并保存此内容.

For this, please add the copied scopes as follows. And please save this.

{
  "timeZone": "### your timezone ###",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": [
    "https://www.googleapis.com/auth/script.scriptapp",
    "scope2",
    "scope3",
    ...
  ]
}

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

After added oauthScopes, at first, please confirm whether your script works fine. And then, remove https://www.googleapis.com/auth/script.scriptapp from oauthScopes, and run again. At this time, if there is an error, it is indicated that the errored line uses the scope of 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之后,请通过逐个删除范围来确认错误行.
    • Also there is a possibility that the authorization Allow this application to run when you are not present is not related to https://www.googleapis.com/auth/script.scriptapp.
      • When you see the scopes in your project, if https://www.googleapis.com/auth/script.scriptapp is not included, after added the scopes to appsscript.json, please confirm the error line by removing scopes one by one.
      • ScriptApp
      • Manifests

      如果这对您没有用,很抱歉.

      If this was not useful for you, I'm sorry.

      这篇关于“当您不在时允许该应用程序运行"在Google Apps脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆