Class Session
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
세션
Session 클래스는 사용자의 이메일 주소 (일부 경우) 및 언어 설정과 같은 세션 정보에 대한 액세스를 제공합니다.
자세한 문서
getActiveUser()
현재 사용자에 대한 정보를 가져옵니다. 보안 정책에서 사용자 ID에 대한 액세스를 허용하지 않으면 User.getEmail()
는 빈 문자열을 반환합니다. 이메일 주소를 사용할 수 있는 상황은 다양합니다. 예를 들어 간단한 onOpen(e)
또는 onEdit(e)
트리거, Google Sheets의 맞춤 함수, '나로 실행' (즉, 사용자 대신 개발자가 승인)하도록 배포된 웹 앱과 같이 사용자의 승인 없이 스크립트를 실행할 수 있는 컨텍스트에서는 사용자의 이메일 주소를 사용할 수 없습니다.
그러나 개발자가 직접 스크립트를 실행하거나 사용자와 동일한 Google Workspace 도메인에 속해 있는 경우에는 일반적으로 이러한 제한사항이 적용되지 않습니다.
// Log the email address of the person running the script.
const email = Session.getActiveUser().getEmail();
Logger.log(email);
리턴
User
: 현재 사용자
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/userinfo.email
getActiveUserLocale()
현재 사용자의 언어 설정을 문자열로 가져옵니다(예: 영어의 경우 en
).
// Log the language setting of the person running the script.
Logger.log(Session.getActiveUserLocale());
리턴
String
: 사용자의 언어 설정을 나타내는 문자열입니다.
getEffectiveUser()
스크립트가 실행되는 사용자의 정보를 가져옵니다. 스크립트가 '나(개발자)로 실행'으로 설정된 웹 앱인 경우 개발자의 사용자 계정이 반환됩니다. 스크립트가 설치 가능한 트리거에서 실행 중인 경우 트리거를 만든 사용자의 계정이 반환됩니다. 대부분의 다른 시나리오에서는 getActiveUser()
와 동일한 계정이 반환됩니다.
// Log the email address of the user under whose authority the script is
// running.
const email = Session.getEffectiveUser().getEmail();
Logger.log(email);
리턴
User
: 스크립트가 실행되는 사용자의 권한
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/userinfo.email
getScriptTimeZone()
스크립트의 시간대를 가져옵니다. 새 스크립트는 기본적으로 소유자의 시간대를 사용하지만 스크립트 편집기에서 File > Project properties를 클릭하여 스크립트의 시간대를 변경할 수 있습니다. 스프레드시트에는 별도의 시간대가 있으며, Google Sheets에서 파일 > 스프레드시트 설정을 클릭하여 변경할 수 있습니다. 스크립트 시간대와 다른 스프레드시트 시간대는 스크립트 버그의 주요 원인입니다.
// Log the time zone of the script.
const timeZone = Session.getScriptTimeZone();
Logger.log(timeZone);
리턴
String
: 스크립트의 시간대
getTemporaryActiveUserKey()
활성 사용자에게 고유하지만 사용자 ID를 노출하지 않는 임시 키를 가져옵니다.
임시 키는 30일마다 순환되며 스크립트에 고유합니다.
// Log the temporary key of the person running the script.
Logger.log(Session.getTemporaryActiveUserKey());
리턴
String
: 임시 활성 사용자 키
지원 중단된 메서드
getTimeZone()
지원 중단되었습니다. 이 함수는 지원 중단되었으며 새 스크립트에서 사용해서는 안 됩니다.
스크립트의 시간대를 가져옵니다. 새 스크립트는 기본적으로 소유자의 시간대를 사용하지만 스크립트 편집기에서 File > Project properties를 클릭하여 스크립트의 시간대를 변경할 수 있습니다. 스프레드시트에는 별도의 시간대가 있으며, Google Sheets에서 파일 > 스프레드시트 설정을 클릭하여 변경할 수 있습니다. 스크립트 시간대와 다른 스프레드시트 시간대는 스크립트 버그의 주요 원인입니다.
// Log the time zone of the script.
const timeZone = Session.getTimeZone();
Logger.log(timeZone);
리턴
String
: 스크립트의 시간대
getUser()
지원 중단되었습니다. 이 함수는 지원 중단되었으며 새 스크립트에서 사용해서는 안 됩니다.
현재 사용자에 대한 정보를 가져옵니다.
리턴
User
: 현재 로그인한 사용자
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/userinfo.email
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 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,["# Class Session\n\nSession\n\nThe Session class provides access to session information, such as the user's email address (in\nsome circumstances) and language setting. \n\n### Methods\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\n### Deprecated 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\n### `get``Active``User()`\n\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\n#### Return\n\n\n[User](/apps-script/reference/base/user) --- the current user\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n`String` --- a string that represents the user's language setting\n\n*** ** * ** ***\n\n### `get``Effective``User()`\n\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\n#### Return\n\n\n[User](/apps-script/reference/base/user) --- the user under whose authority the script is running\n\n#### Authorization\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()`\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.getScriptTimeZone();\nLogger.log(timeZone);\n```\n\n#### Return\n\n\n`String` --- the time zone of the script\n\n*** ** * ** ***\n\n### `get``Temporary``Active``User``Key()`\n\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\n#### Return\n\n\n`String` --- the temporary active user key\n\nDeprecated methods\n------------------\n\n### `get``Time``Zone()`\n\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\n#### Return\n\n\n`String` --- the time zone of the script\n\n*** ** * ** ***\n\n### `get``User()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets information about the current user.\n\n#### Return\n\n\n[User](/apps-script/reference/base/user) --- the currently signed in user\n\n#### Authorization\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`"]]