Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
Sessione
La classe Session fornisce l'accesso alle informazioni sulla sessione, ad esempio l'indirizzo email dell'utente (in alcune circostanze) e l'impostazione della lingua.
Recupera le informazioni sull'utente corrente. Se i criteri di sicurezza non consentono l'accesso all'identità dell'utente, User.getEmail() restituisce una stringa vuota. Le circostanze in cui l'indirizzo email è disponibile variano: ad esempio, l'indirizzo email dell'utente non è disponibile in nessun contesto che consenta l'esecuzione di uno script senza l'autorizzazione dell'utente, come un semplice attivatore onOpen(e) o onEdit(e), una funzione personalizzata in Fogli Google o un'app web di cui è stato eseguito il deployment per l'esecuzione come utente (ovvero autorizzata dallo sviluppatore anziché dall'utente). Tuttavia, in genere queste limitazioni non si applicano se lo sviluppatore esegue lo script autonomamente o appartiene allo stesso dominio Google Workspace dell'utente.
// Log the email address of the person running the script.constemail=Session.getActiveUser().getEmail();Logger.log(email);
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
https://www.googleapis.com/auth/userinfo.email
getActiveUserLocale()
Restituisce l'impostazione della lingua dell'utente corrente come stringa, ad esempio en per l'inglese.
// Log the language setting of the person running the script.Logger.log(Session.getActiveUserLocale());
Invio
String: una stringa che rappresenta l'impostazione della lingua dell'utente
getEffectiveUser()
Recupera le informazioni sull'utente sotto la cui autorità viene eseguito lo script. Se lo script è un'app web impostata su "Esegui come me" (lo sviluppatore), viene restituito l'account utente dello sviluppatore. Se lo script viene eseguito in un attivatore installabile, viene restituito l'account dell'utente che ha creato l'attivatore. Nella maggior parte degli altri scenari, viene restituito lo stesso account di getActiveUser().
// Log the email address of the user under whose authority the script is// running.constemail=Session.getEffectiveUser().getEmail();Logger.log(email);
Invio
User: l'utente sotto la cui autorità viene eseguito lo script
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
https://www.googleapis.com/auth/userinfo.email
getScriptTimeZone()
Recupera il fuso orario dello script. Per impostazione predefinita, i nuovi script utilizzano il fuso orario del proprietario, ma il fuso orario dello script può essere modificato facendo clic su File > Proprietà del progetto nell'editor di script. Tieni presente che i fogli di lavoro hanno un fuso orario separato, che può essere modificato facendo clic su File > Impostazioni foglio di lavoro in Fogli Google. I fusi orari dei fogli di lavoro diversi da quello dello script sono una fonte frequente di bug di scripting.
// Log the time zone of the script.consttimeZone=Session.getScriptTimeZone();Logger.log(timeZone);
Invio
String: il fuso orario dello script
getTemporaryActiveUserKey()
Recupera una chiave temporanea univoca per l'utente attivo, ma non rivela la sua identità. La chiave temporanea viene ruotata ogni 30 giorni ed è univoca per lo script.
// Log the temporary key of the person running the script.Logger.log(Session.getTemporaryActiveUserKey());
Invio
String: la chiave utente attiva temporanea
Metodi ritirati
getTimeZone()
Ritiro. Questa funzione è deprecata e non deve essere utilizzata nei nuovi script.
Recupera il fuso orario dello script. Per impostazione predefinita, i nuovi script utilizzano il fuso orario del proprietario, ma il fuso orario dello script può essere modificato facendo clic su File > Proprietà del progetto nell'editor di script. Tieni presente che i fogli di lavoro hanno un fuso orario separato, che può essere modificato facendo clic su File > Impostazioni foglio di lavoro in Fogli Google. I fusi orari dei fogli di lavoro diversi da quello dello script sono una fonte frequente di bug di scripting.
// Log the time zone of the script.consttimeZone=Session.getTimeZone();Logger.log(timeZone);
Invio
String: il fuso orario dello script
getUser()
Ritiro. Questa funzione è deprecata e non deve essere utilizzata nei nuovi script.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-26 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eSession\u003c/code\u003e class in Apps Script allows you to access information about the current user and the script's environment, such as the user's locale and the script's time zone.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve information about the active user, effective user, script time zone, and a temporary active user key using methods like \u003ccode\u003egetActiveUser()\u003c/code\u003e, \u003ccode\u003egetEffectiveUser()\u003c/code\u003e, \u003ccode\u003egetScriptTimeZone()\u003c/code\u003e, and \u003ccode\u003egetTemporaryActiveUserKey()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eSome methods like \u003ccode\u003egetTimeZone()\u003c/code\u003e and \u003ccode\u003egetUser()\u003c/code\u003e are deprecated and should be replaced with their updated counterparts such as \u003ccode\u003egetScriptTimeZone()\u003c/code\u003e and \u003ccode\u003egetActiveUser()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhile the user's email address can be accessed in certain circumstances using \u003ccode\u003egetActiveUser().getEmail()\u003c/code\u003e or \u003ccode\u003egetEffectiveUser().getEmail()\u003c/code\u003e, it may not be available if security policies restrict access or in contexts without explicit user authorization.\u003c/p\u003e\n"],["\u003cp\u003eAccessing user information may require specific authorization scopes, like \u003ccode\u003ehttps://www.googleapis.com/auth/userinfo.email\u003c/code\u003e, to be granted to the script.\u003c/p\u003e\n"]]],[],null,["Session\n\nThe Session class provides access to session information, such as the user's email address (in\nsome circumstances) and language setting. \n\nMethods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------|------------------------------------------|-----------------------------------------------------------------------------------------------|\n| [getActiveUser()](#getActiveUser()) | [User](/apps-script/reference/base/user) | Gets information about the current user. |\n| [getActiveUserLocale()](#getActiveUserLocale()) | `String` | Gets the language setting of the current user as a string---for example, `en` for English. |\n| [getEffectiveUser()](#getEffectiveUser()) | [User](/apps-script/reference/base/user) | Gets information about the user under whose authority the script is running. |\n| [getScriptTimeZone()](#getScriptTimeZone()) | `String` | Gets the time zone of the script. |\n| [getTemporaryActiveUserKey()](#getTemporaryActiveUserKey()) | `String` | Gets a temporary key that is unique to the active user but does not reveal the user identity. |\n\nDeprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------|------------------------------------------|------------------------------------------|\n| [getTimeZone()](#getTimeZone()) | `String` | Gets the time zone of the script. |\n| [getUser()](#getUser()) | [User](/apps-script/reference/base/user) | Gets information about the current user. |\n\nDetailed documentation \n\n`get``Active``User()` \nGets information about the current user. If security policies do not allow access to the user's\nidentity, [User.getEmail()](/apps-script/reference/base/user#getEmail()) returns a blank string. The circumstances in which the\nemail address is available vary: for example, the user's email address is not available in any\ncontext that allows a script to run without that user's authorization, like a simple `on``Open(e)` or `on``Edit(e)` trigger, a custom function in Google Sheets, or a web app\ndeployed to \"execute as me\" (that is, authorized by the developer instead of the user).\nHowever, these restrictions generally do not apply if the developer runs the script themselves\nor belongs to the same Google Workspace domain as the user.\n\n```javascript\n// Log the email address of the person running the script.\nconst email = Session.getActiveUser().getEmail();\nLogger.log(email);\n```\n\nReturn\n\n\n[User](/apps-script/reference/base/user) --- the current user\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/userinfo.email`\n\n*** ** * ** ***\n\n`get``Active``User``Locale()` \nGets the language setting of the current user as a string---for example, `en` for English.\n\n```javascript\n// Log the language setting of the person running the script.\nLogger.log(Session.getActiveUserLocale());\n```\n\nReturn\n\n\n`String` --- a string that represents the user's language setting\n\n*** ** * ** ***\n\n`get``Effective``User()` \nGets information about the user under whose authority the script is running. If the script is a\nweb app set to \"execute as me\" (the developer), this returns the developer's user account. If\nthe script is running under an [installable\ntrigger](/apps-script/understanding_triggers), this returns the account of the user who created the trigger. In most other\nscenarios, this returns the same account as [getActiveUser()](#getActiveUser()).\n\n```javascript\n// Log the email address of the user under whose authority the script is\n// running.\nconst email = Session.getEffectiveUser().getEmail();\nLogger.log(email);\n```\n\nReturn\n\n\n[User](/apps-script/reference/base/user) --- the user under whose authority the script is running\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/userinfo.email`\n\n*** ** * ** ***\n\n`get``Script``Time``Zone()` \nGets the time zone of the script. New scripts default to the owner's time zone, but the\nscript's time zone can be changed by clicking **File \\\u003e Project properties** in the script\neditor. Note that spreadsheets have a separate time zone, which can be changed by clicking\n**File \\\u003e Spreadsheet settings** in Google Sheets. Spreadsheet time zones that differ from\nthe script time zone are a frequent source of scripting bugs.\n\n```javascript\n// Log the time zone of the script.\nconst timeZone = Session.getScriptTimeZone();\nLogger.log(timeZone);\n```\n\nReturn\n\n\n`String` --- the time zone of the script\n\n*** ** * ** ***\n\n`get``Temporary``Active``User``Key()` \nGets a temporary key that is unique to the active user but does not reveal the user identity.\nThe temporary key rotates every 30 days and is unique to the script.\n\n```javascript\n// Log the temporary key of the person running the script.\nLogger.log(Session.getTemporaryActiveUserKey());\n```\n\nReturn\n\n\n`String` --- the temporary active user key\n\nDeprecated methods \n\n`get``Time``Zone()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the time zone of the script. New scripts default to the owner's time zone, but the\nscript's time zone can be changed by clicking **File \\\u003e Project properties** in the script\neditor. Note that spreadsheets have a separate time zone, which can be changed by clicking\n**File \\\u003e Spreadsheet settings** in Google Sheets. Spreadsheet time zones that differ from\nthe script time zone are a frequent source of scripting bugs.\n\n```javascript\n// Log the time zone of the script.\nconst timeZone = Session.getTimeZone();\nLogger.log(timeZone);\n```\n\nReturn\n\n\n`String` --- the time zone of the script\n\n*** ** * ** ***\n\n`get``User()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets information about the current user.\n\nReturn\n\n\n[User](/apps-script/reference/base/user) --- the currently signed in user\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/userinfo.email`"]]