Enum AuthMode
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
AuthMode
Un'enumerazione che identifica le categorie di servizi autorizzati che Apps Script è in grado di eseguire tramite una funzione attivata. Questi valori sono esposti nelle funzioni attivate come proprietà authMode
del parametro evento e
. Per maggiori informazioni, consulta la guida al ciclo di vita dell'autorizzazione per i componenti aggiuntivi.
Per chiamare un enum, devi chiamare la relativa classe, il nome e la proprietà di base. Ad esempio,
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();
}
Proprietà
Proprietà | Tipo | Descrizione |
NONE | Enum | Una modalità che non consente l'accesso a servizi che richiedono l'autorizzazione. Questa modalità si verifica
quando un componente aggiuntivo esegue un trigger semplice onOpen(e) e l'utente ha installato un
componente aggiuntivo in un altro documento, ma il componente aggiuntivo non è stato utilizzato nel documento corrente. |
CUSTOM_FUNCTION | Enum | Una modalità che consente l'accesso a un sottoinsieme limitato di servizi da utilizzare nelle funzioni di un foglio di lavoro personalizzato. Alcuni di questi servizi, tra cui l'accesso di sola lettura al servizio Fogli, normalmente richiedono l'autorizzazione, ma sono consentiti senza autorizzazione se utilizzati in una funzione personalizzata. Poiché le funzioni personalizzate non includono un parametro evento, questo valore non viene mai restituito. È documentato solo per dimostrare che le funzioni personalizzate vengono eseguite nella loro modalità di autorizzazione. |
LIMITED | Enum | Una modalità che consente l'accesso a un sottoinsieme limitato di servizi. Questa modalità si verifica quando un componente aggiuntivo o uno script legato a un documento esegue un attivatore semplice onOpen(e) o onEdit(e) , tranne nel caso descritto per NONE . |
FULL | Enum | Una modalità che consente l'accesso a tutti i servizi che richiedono l'autorizzazione. Questa modalità si verifica quando un plug-in o uno script viene eseguito come risultato di qualsiasi attivatore diverso dai casi descritti per LIMITED o NONE . |
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 UTC."],[[["\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`. |"]]