为什么我的插件要求获得此权限?尝试浏览文档但找不到任何内容。
据我所知,当用户不在时,我的应用程序不会运行! (它要求用户在Google表格中选择范围,在自定义UI中按下按钮,然后调用外部API)。是否有任何提示我应该寻找什么来查找触发此类权限请求的有问题的代码或配置?
答案 0 :(得分:5)
这个答案怎么样?
允许此应用程序在您不在时运行
当显示上述授权消息时,表示在项目中使用了使用https://www.googleapis.com/auth/script.scriptapp
范围的方法。您可以在File - >中看到项目中的范围。项目属性 - >作用域。需要这种范围的方法特别是ScriptApp
。在项目中使用getProjectTriggers()
,getUserTriggers()
,deleteTrigger()
,newTrigger()
时,会自动检测此范围。
如果您已经注意到在项目中使用了这样的方法,那么本节可能就是答案。
如果您已经注意到项目中使用了 NOT 这样的方法,请查看此部分。
保存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
。
如果要确认是否需要使用此类作用域的授权来运行脚本,可以使用&#34; Manifests&#34;来执行此操作。最近,#34; Manifests&#34;被添加到GAS项目中。使用&#34; Manifests&#34;,可以停止自动检测范围。通过这种方式,您可以了解检测到的范围是否实际上是项目所需的。为了确认这一点,请执行以下操作。
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 present
可能与https://www.googleapis.com/auth/script.scriptapp
无关。
https://www.googleapis.com/auth/script.scriptapp
,则在将范围添加到appsscript.json
后,请通过逐个删除范围来确认错误行。如果这对你没用,我很抱歉。
答案 1 :(得分:0)
我的附加组件出现此问题,并意识到script.scriptapp
范围已被自动检测到,因为我已实施onOpen
和onInstall
方法(以安装附加组件)菜单项)。
如果要查看为Google应用脚本检测到的范围,请在“脚本编辑器”中选择“项目属性”,然后选择“范围”选项卡。
此代码直接来自Google Add-on's tutorial - 很可惜它会导致如此可怕的查看权限请求。
/**
* Creates a menu entry in the Google Docs UI when the document is opened.
* This method is only used by the regular add-on, and is never called by
* the mobile add-on version.
*
* @param {object} e The event parameter for a simple onOpen trggr. To
* determine which authorization mode (ScriptApp.AuthMode) the trggr is
* running in, inspect e.authMode.
*/
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Start', 'showSidebar')
.addToUi();
}
/**
* Runs when the add-on is installed.
* This method is only used by the regular add-on, and is never called by
* the mobile add-on version.
*
* @param {object} e The event parameter for a simple onInstall trggr. To
* determine which authorization mode (ScriptApp.AuthMode) the trggr is
* running in, inspect e.authMode. (In practice, onInstall trggrs always
* run in AuthMode.FULL, but onOpen may be AuthMode.LIMITED or
* AuthMode.NONE.)
*/
function onInstall(e) {
onOpen(e);
}
答案 2 :(得分:0)
我在附加组件之一中遇到了同样的问题。问题在于默认的Google模板具有一些注释,这些注释将触发此范围的检测。
@param {object} e The event parameter for a simple onOpen trigger. To
determine which authorization mode (ScriptApp.AuthMode) the trigger is
running in, inspect e.authMode.
@param {object} e The event parameter for a simple onInstall trigger. To
determine which authorization mode (ScriptApp.AuthMode) the trigger is
running in, inspect e.authMode. (In practice, onInstall triggers always
run in AuthMode.FULL, but onOpen triggers may be AuthMode.LIMITED or
AuthMode.NONE.)
如果您确定不在项目的其他任何地方使用此范围(使用编程触发器,使用ScriptApp等),请删除这些注释,然后将删除范围。