Enum AuthMode
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
AuthMode
一个枚举,用于确定 Apps Script 能够通过触发的函数执行哪些类别的已获授权服务。这些值会在触发的函数中作为事件参数 e
的 authMode
属性公开。如需了解详情,请参阅插件授权生命周期指南。
如需调用枚举,您可以调用其父类、名称和属性。例如
ScriptApp.AuthMode.CUSTOM_FUNCTION
。
function onOpen(e) {
const menu = SpreadsheetApp.getUi().createAddonMenu();
if (e && e.authMode === ScriptApp.AuthMode.NONE) {
// Add a normal menu item (works in all authorization modes).
menu.addItem('Start workflow', 'startWorkflow');
} else {
// Add a menu item based on properties (doesn't work in AuthMode.NONE).
const properties = PropertiesService.getDocumentProperties();
const workflowStarted = properties.getProperty('workflowStarted');
if (workflowStarted) {
menu.addItem('Check workflow status', 'checkWorkflow');
} else {
menu.addItem('Start workflow', 'startWorkflow');
}
// Record analytics.
UrlFetchApp.fetch('http://www.example.com/analytics?event=open');
}
menu.addToUi();
}
属性
属性 | 类型 | 说明 |
NONE | Enum | 此模式不允许访问任何需要授权的服务。当插件执行 onOpen(e) 简单触发器,并且用户已在其他文档中安装插件,但该插件尚未在当前文档中使用时,就会出现此模式。 |
CUSTOM_FUNCTION | Enum | 此模式允许访问一小部分服务,以便在自定义电子表格函数中使用。其中一些服务(包括对 Google 表格服务的只读访问权限)通常需要授权,但在自定义函数中使用时,无需授权即可。由于自定义函数不包含事件参数,因此系统绝不会返回此值;记录此值只是为了证明自定义函数在自己的授权模式下运行。 |
LIMITED | Enum | 一种模式,允许访问一小部分服务。当绑定到文档的插件或脚本执行 onOpen(e) 或 onEdit(e) 简单触发器时,就会出现此模式,但 NONE 所述的情况除外。 |
FULL | Enum | 一种模式,允许访问需要授权的所有服务。如果是在 LIMITED 或 NONE 中所述情况以外的任何触发器的结果下执行了插件或脚本,则会出现此模式。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eAuthMode defines the level of access Apps Script has to authorized services when a triggered function is executed.\u003c/p\u003e\n"],["\u003cp\u003eIt's crucial for understanding how add-ons and scripts interact with Google services, especially concerning user authorization.\u003c/p\u003e\n"],["\u003cp\u003eDifferent AuthModes like NONE, LIMITED, and FULL, dictate the scope of service access, impacting functionalities within triggered functions.\u003c/p\u003e\n"],["\u003cp\u003eCustom functions operate under a specific authorization mode that allows restricted access to certain services without explicit user authorization.\u003c/p\u003e\n"]]],[],null,["# Enum AuthMode\n\nAuthMode\n\nAn enumeration that identifies which categories of authorized services Apps Script is able to\nexecute through a triggered function. These values are exposed in [triggered functions](/apps-script/understanding_triggers) as the `auth``Mode`\nproperty of the [event parameter](/apps-script/understanding_events), `e`. For\nmore information, see the [guide to the\nauthorization lifecycle for add-ons](/gsuite/add-ons/concepts/addon-authorization#authorization_modes).\n\nTo call an enum, you call its parent class, name, and property. For example, `\nScriptApp.AuthMode.CUSTOM_FUNCTION`.\n\n```javascript\nfunction onOpen(e) {\n const menu = SpreadsheetApp.getUi().createAddonMenu();\n if (e && e.authMode === ScriptApp.AuthMode.NONE) {\n // Add a normal menu item (works in all authorization modes).\n menu.addItem('Start workflow', 'startWorkflow');\n } else {\n // Add a menu item based on properties (doesn't work in AuthMode.NONE).\n const properties = PropertiesService.getDocumentProperties();\n const workflowStarted = properties.getProperty('workflowStarted');\n if (workflowStarted) {\n menu.addItem('Check workflow status', 'checkWorkflow');\n } else {\n menu.addItem('Start workflow', 'startWorkflow');\n }\n // Record analytics.\n UrlFetchApp.fetch('http://www.example.com/analytics?event=open');\n }\n menu.addToUi();\n}\n``` \n\n### Properties\n\n| Property | Type | Description |\n|-------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `NONE` | `Enum` | A mode that does not allow access to any services that require authorization. This mode occurs when an add-on executes an `on``Open(e)` simple trigger, and the user has installed an add-on in a different document but the add-on has not been used in the current document. |\n| `CUSTOM_FUNCTION` | `Enum` | A mode that allows access to a limited subset of services for use in custom spreadsheet functions. Some of these services --- including read-only access to Spreadsheet service --- normally require authorization, but are permitted without authorization when used in a custom function. Because custom functions do not include an event parameter, this value is never returned; it is documented only to demonstrate that custom functions run in their own authorization mode. |\n| `LIMITED` | `Enum` | A mode that allows access to a limited subset of services. This mode occurs when an add-on or a script [bound](/apps-script/scripts_containers) to a document executes an `on``Open(e)` or `on``Edit(e)` simple trigger, except in the case described for `NONE`. |\n| `FULL` | `Enum` | A mode that allows access to all services that require authorization. This mode occurs when an add-on or a script executes as the result of any trigger other than the cases described for `LIMITED` or `NONE`. |"]]