Enum AuthMode
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
AuthMode
การแจกแจงที่ระบุหมวดหมู่ของบริการที่ได้รับอนุญาตซึ่ง Apps Script สามารถดำเนินการผ่านฟังก์ชันที่ทริกเกอร์ ค่าเหล่านี้จะแสดงในฟังก์ชันที่ทริกเกอร์เป็นauthMode
พร็อพเพอร์ตี้ของพารามิเตอร์เหตุการณ์ e
ดูข้อมูลเพิ่มเติมได้ในคู่มือเกี่ยวกับวงจรการให้สิทธิ์สําหรับส่วนเสริม
หากต้องการเรียกใช้ enum ให้เรียกคลาสหลัก ชื่อ และพร็อพเพอร์ตี้ของ enum นั้น เช่น
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();
}
พร็อพเพอร์ตี้
พร็อพเพอร์ตี้ | ประเภท | คำอธิบาย |
NONE | Enum | โหมดที่ไม่อนุญาตให้เข้าถึงบริการใดๆ ก็ตามที่ต้องได้รับอนุญาต โหมดนี้เกิดขึ้นเมื่อส่วนเสริมเรียกใช้onOpen(e) ทริกเกอร์แบบง่าย และผู้ใช้ได้ติดตั้งส่วนเสริมในเอกสารอื่น แต่ไม่ได้ใช้งานส่วนเสริมในเอกสารปัจจุบัน |
CUSTOM_FUNCTION | Enum | โหมดที่อนุญาตให้เข้าถึงบริการชุดย่อยแบบจำกัดเพื่อใช้ในฟังก์ชันสเปรดชีตที่กำหนดเอง บริการบางอย่างเหล่านี้ ซึ่งรวมถึงสิทธิ์การอ่านอย่างเดียวสำหรับบริการสเปรดชีต ปกติจะต้องได้รับสิทธิ์ แต่จะได้รับอนุญาตโดยไม่ต้องขอสิทธิ์เมื่อใช้ในฟังก์ชันที่กำหนดเอง เนื่องจากฟังก์ชันที่กําหนดเองไม่มีพารามิเตอร์เหตุการณ์ ระบบจึงจะไม่แสดงค่านี้ แต่จะแสดงเพื่อแสดงให้เห็นว่าฟังก์ชันที่กําหนดเองทํางานในโหมดการให้สิทธิ์ของตนเองเท่านั้น |
LIMITED | Enum | โหมดที่อนุญาตให้เข้าถึงบริการชุดย่อยแบบจำกัด โหมดนี้เกิดขึ้นเมื่อส่วนเสริมหรือสคริปต์ที่เชื่อมโยงกับเอกสารเรียกใช้ทริกเกอร์แบบง่าย onOpen(e) หรือ onEdit(e) ยกเว้นในกรณีที่อธิบายไว้สำหรับ NONE |
FULL | Enum | โหมดที่อนุญาตให้เข้าถึงบริการทั้งหมดที่ต้องได้รับสิทธิ์ โหมดนี้จะเกิดขึ้นเมื่อส่วนเสริมหรือสคริปต์ทำงานเป็นผลมาจากทริกเกอร์ใดๆ นอกเหนือจากกรณีที่อธิบายสำหรับ LIMITED หรือ NONE |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 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`. |"]]