Class AuthorizationInfo
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
AuthorizationInfo
ออบเจ็กต์ที่ตรวจสอบว่าผู้ใช้ได้ให้สิทธิ์สําหรับขอบเขตที่จําเป็นสคริปต์หรือไม่ นอกจากนี้ ออบเจ็กต์ยังมี URL การให้สิทธิ์เพื่อให้ผู้ใช้ให้สิทธิ์เหล่านั้นด้วย
การเรียกใช้สคริปต์บางรายการอาจเริ่มต้นได้โดยไม่ต้องได้รับความยินยอมจากผู้ใช้สำหรับขอบเขตที่จําเป็นทั้งหมดที่สคริปต์ใช้ ข้อมูลในออบเจ็กต์นี้ช่วยให้คุณควบคุมการเข้าถึงส่วนต่างๆ ของโค้ดที่ต้องใช้ขอบเขตที่เฉพาะเจาะจง และขอสิทธิ์สำหรับขอบเขตเหล่านั้นสำหรับการเรียกใช้ครั้งต่อๆ ไป
ScriptApp.getAuthorizationInfo(authMode)
ส่งคืนออบเจ็กต์นี้ เกือบทุกกรณี สคริปต์ควรเรียกใช้ ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL)
เนื่องจากไม่มีโหมดการให้สิทธิ์อื่นที่กําหนดให้ผู้ใช้ต้องให้สิทธิ์
เอกสารประกอบโดยละเอียด
getAuthorizationStatus()
รับค่าที่ระบุว่าผู้ใช้ต้องให้สิทธิ์สคริปต์นี้เพื่อใช้บริการอย่างน้อย 1 รายการหรือไม่ (เช่น ScriptApp.AuthorizationStatus.REQUIRED
)
// Log the authorization status (REQUIRED or NOT_REQUIRED).
const authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
Logger.log(authInfo.getAuthorizationStatus());
รีเทิร์น
AuthorizationStatus
— สถานะการให้สิทธิ์
getAuthorizationUrl()
รับ URL การให้สิทธิ์ที่สามารถใช้เพื่อมอบสิทธิ์เข้าถึงสคริปต์ เมธอดนี้จะแสดงผล null
หากไม่จําเป็นต้องได้รับอนุญาต หน้าเว็บที่ URL จะปิดโดยอัตโนมัติหากมีการเข้าถึงและสคริปต์ไม่จําเป็นต้องได้รับสิทธิ์
// Log the URL used to grant access to the script.
const authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
Logger.log(authInfo.getAuthorizationUrl());
รีเทิร์น
String
— URL ที่สามารถใช้เพื่อให้สิทธิ์สคริปต์
getAuthorizedScopes()
รับรายการขอบเขตที่ได้รับอนุญาตสำหรับสคริปต์ หากมีการขอข้อมูลการให้สิทธิ์สำหรับรายการขอบเขตที่ระบุ ระบบจะแสดงผลขอบเขตที่ได้รับอนุญาตจากรายการที่ระบุ
// Logs which scopes in the specified list have been authorized for the script.
const authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL, [
'https: //www.googleapis.com/auth/documents',
'https: //www.googleapis.com/auth/spreadsheets',
]);
Logger.log(authInfo.getAuthorizedScopes());
รีเทิร์น
String[]
— รายการขอบเขตที่ได้รับอนุญาต
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eAuthorizationInfo is an object used to determine if a user needs to authorize a script to use services and provides the authorization dialog URL.\u003c/p\u003e\n"],["\u003cp\u003eThis object is primarily used in add-ons with installable triggers to manage user access or prompt for authorization.\u003c/p\u003e\n"],["\u003cp\u003eIt offers two methods: \u003ccode\u003egetAuthorizationStatus()\u003c/code\u003e to check if authorization is required, and \u003ccode\u003egetAuthorizationUrl()\u003c/code\u003e to obtain the authorization URL.\u003c/p\u003e\n"],["\u003cp\u003eScripts should generally use \u003ccode\u003eScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL)\u003c/code\u003e for comprehensive authorization checks.\u003c/p\u003e\n"]]],[],null,["# Class AuthorizationInfo\n\nAuthorizationInfo\n\nAn object that checks if the user has granted authorization for the required scopes of the\nscript. The object also provides an authorization URL for users to grant those permissions.\n\nSome script executions can start without a user's consent to all required scopes used by the\nscript. The information in this object lets you control access to sections of code that require\ncertain scopes and request authorization of those scopes for subsequent executions.\n\nThis object is returned by [ScriptApp.getAuthorizationInfo(authMode)](/apps-script/reference/script/script-app#getAuthorizationInfo(AuthMode)). In almost\nall cases, scripts should call `Script``App.getAuthorizationInfo(ScriptApp.AuthMode.FULL)`,\nsince no other authorization mode requires that users grant authorization. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getAuthorizationStatus()](#getAuthorizationStatus()) | [AuthorizationStatus](/apps-script/reference/script/authorization-status) | Gets a value that indicates whether the user needs to authorize this script to use one or more services (for example, `Script``App.AuthorizationStatus.REQUIRED`). |\n| [getAuthorizationUrl()](#getAuthorizationUrl()) | `String` | Gets the authorization URL that can be used to grant access to the script. |\n| [getAuthorizedScopes()](#getAuthorizedScopes()) | `String[]` | Gets a list of authorized scopes for the script. |\n\nDetailed documentation\n----------------------\n\n### `get``Authorization``Status()`\n\nGets a value that indicates whether the user needs to authorize this script to use one or more\nservices (for example, `Script``App.AuthorizationStatus.REQUIRED`).\n\n```javascript\n// Log the authorization status (REQUIRED or NOT_REQUIRED).\nconst authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);\nLogger.log(authInfo.getAuthorizationStatus());\n```\n\n#### Return\n\n\n[AuthorizationStatus](/apps-script/reference/script/authorization-status) --- the authorization status\n\n*** ** * ** ***\n\n### `get``Authorization``Url()`\n\nGets the authorization URL that can be used to grant access to the script. This method returns\n`null` if no authorization is required. The page at the URL will close automatically if\nit is accessed and the script does not require any authorization.\n\n```javascript\n// Log the URL used to grant access to the script.\nconst authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);\nLogger.log(authInfo.getAuthorizationUrl());\n```\n\n#### Return\n\n\n`String` --- a URL that can be used to authorize the script\n\n*** ** * ** ***\n\n### `get``Authorized``Scopes()`\n\nGets a list of authorized scopes for the script. If authorization information is requested for\na specified list of scopes, returns the authorized scopes from the specified list.\n\n```javascript\n// Logs which scopes in the specified list have been authorized for the script.\nconst authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL, [\n 'https: //www.googleapis.com/auth/documents',\n 'https: //www.googleapis.com/auth/spreadsheets',\n]);\nLogger.log(authInfo.getAuthorizedScopes());\n```\n\n#### Return\n\n\n`String[]` --- The list of authorized scopes."]]