Class User
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
משתמש
ייצוג של משתמש, מתאים לכתיבה של סקריפטים.
Methods
שיטה | סוג הערך המוחזר | תיאור קצר |
getEmail() | String | הפונקציה מקבלת את כתובת האימייל של המשתמש, אם היא זמינה. |
שיטות שהוצאו משימוש
שיטה | סוג הערך המוחזר | תיאור קצר |
getUserLoginId()
| String | הפונקציה מקבלת את כתובת האימייל של המשתמש. |
מסמכים מפורטים
getEmail()
הפונקציה מקבלת את כתובת האימייל של המשתמש, אם היא זמינה. אם מדיניות האבטחה לא מאפשרת גישה לכתובת האימייל של המשתמש, השיטה הזו מחזירה מחרוזת ריקה. הנסיבות שבהן כתובת האימייל זמינה משתנות: לדוגמה, כתובת האימייל של המשתמש לא זמינה בכל הקשר שמאפשר להריץ סקריפט בלי הרשאה מהמשתמש הזה, כמו טריגר פשוט של onOpen(e)
או onEdit(e)
, פונקציה מותאמת אישית ב-Google Sheets או אפליקציית אינטרנט שנפרסה ל'הפעלה בתור 'אני' (כלומר, הרשאה מהמפתח במקום מהמשתמש).
עם זאת, בדרך כלל המגבלות האלה לא חלות אם המפתח מפעיל את הסקריפט בעצמו או שייך לאותו דומיין Google Workspace כמו המשתמש.
// Log the email address of the person running the script.
Logger.log(Session.getActiveUser().getEmail());
חזרה
String
– כתובת האימייל של המשתמש, או מחרוזת ריקה אם מדיניות האבטחה לא מאפשרת גישה לכתובת האימייל של המשתמש.
שיטות שהוצאו משימוש
getUserLoginId()
הוצא משימוש. החל מ-24 ביוני 2013, הוחלף על ידי getEmail()
.
הפונקציה מקבלת את כתובת האימייל של המשתמש.
// Log the email address of the person running the script.
Logger.log(Session.getActiveUser().getUserLoginId());
חזרה
String
– כתובת האימייל של המשתמש.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003eRepresents a user for scripting purposes, providing methods to access user information.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetEmail()\u003c/code\u003e retrieves the user's email address if permitted by security policies, returning a blank string otherwise.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetUserLoginId()\u003c/code\u003e is deprecated and replaced by \u003ccode\u003egetEmail()\u003c/code\u003e for retrieving the user's email address.\u003c/p\u003e\n"],["\u003cp\u003eAccess to the user's email address might be restricted in certain contexts due to security considerations, such as unauthorized script execution.\u003c/p\u003e\n"]]],[],null,["# Class User\n\nUser\n\nRepresentation of a user, suitable for scripting. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------|-------------|----------------------------------------------|\n| [getEmail()](#getEmail()) | `String` | Gets the user's email address, if available. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------------|-------------|--------------------------------|\n| [getUserLoginId()](#getUserLoginId()) | `String` | Gets the user's email address. |\n\nDetailed documentation\n----------------------\n\n### `get``Email()`\n\nGets the user's email address, if available. If security policies do not allow access to the\nuser's email address, this method returns a blank string. The circumstances in which the email\naddress 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.\nLogger.log(Session.getActiveUser().getEmail());\n```\n\n#### Return\n\n\n`String` --- The user's email's address, or a blank string if security policies do not allow access\nto the user's email address.\n\nDeprecated methods\n------------------\n\n### `get``User``Login``Id()`\n\n\n**Deprecated.** As of June 24, 2013, replaced by [getEmail()](#getEmail()).\n\nGets the user's email address.\n\n```javascript\n// Log the email address of the person running the script.\nLogger.log(Session.getActiveUser().getUserLoginId());\n```\n\n#### Return\n\n\n`String` --- The user's email's address."]]