Class User
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ผู้ใช้
การนําเสนอผู้ใช้ ซึ่งเหมาะกับสคริปต์
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
getEmail() | String | รับอีเมลของผู้ใช้ หากมี |
เอกสารประกอบโดยละเอียด
getEmail()
รับอีเมลของผู้ใช้ หากมี หากนโยบายความปลอดภัยไม่อนุญาตให้เข้าถึงอีเมลของผู้ใช้ เมธอดนี้จะแสดงผลสตริงว่าง บริบทที่อีเมลพร้อมใช้งานจะแตกต่างกันไป เช่น อีเมลของผู้ใช้จะไม่พร้อมใช้งานในบริบทใดก็ตามที่อนุญาตให้สคริปต์ทำงานโดยไม่ได้รับอนุญาตจากผู้ใช้รายนั้น เช่น ทริกเกอร์ onOpen(e)
หรือ onEdit(e)
ธรรมดา ฟังก์ชันที่กำหนดเองใน Google ชีต หรือเว็บแอปที่ทําให้ "เรียกใช้ในฐานะฉัน" (นั่นคือ ได้รับอนุญาตจากนักพัฒนาซอฟต์แวร์แทนผู้ใช้)
อย่างไรก็ตาม โดยทั่วไปแล้ว ข้อจำกัดเหล่านี้จะไม่มีผลหากนักพัฒนาซอฟต์แวร์เรียกใช้สคริปต์ด้วยตนเองหรืออยู่ในโดเมน Google Workspace เดียวกับผู้ใช้
// Log the email address of the person running the script.
Logger.log(Session.getActiveUser().getEmail());
รีเทิร์น
String
— อีเมลของผู้ใช้ หรือสตริงว่างหากนโยบายความปลอดภัยไม่อนุญาตให้เข้าถึงอีเมลของผู้ใช้
วิธีการที่เลิกใช้งาน
getUserLoginId()
เลิกใช้งานแล้ว แทนที่ด้วย getEmail()
ตั้งแต่วันที่ 24 มิถุนายน 2013
รับอีเมลของผู้ใช้
// Log the email address of the person running the script.
Logger.log(Session.getActiveUser().getUserLoginId());
รีเทิร์น
String
— อีเมลของผู้ใช้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 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."]]