Apps Script tự động xác định các phạm vi uỷ quyền (chẳng hạn như truy cập vào các tệp Google Trang tính hoặc Gmail của bạn) dựa trên quá trình quét mã. Mã được nhận xét vẫn có thể tạo yêu cầu uỷ quyền. Nếu một tập lệnh cần được uỷ quyền, bạn sẽ thấy một trong các hộp thoại uỷ quyền xuất hiện ở đây khi tập lệnh đó chạy.
Các tập lệnh mà bạn đã uỷ quyền trước đó cũng sẽ yêu cầu bạn uỷ quyền thêm nếu một thay đổi về mã thêm các dịch vụ mới. Tập lệnh có thể không yêu cầu uỷ quyền nếu bạn truy cập vào tập lệnh dưới dạng một ứng dụng web chạy theo danh tính người dùng của chủ sở hữu tập lệnh.
Thu hồi quyền truy cập
Để thu hồi quyền truy cập của một tập lệnh vào dữ liệu của bạn, hãy làm theo các bước sau:
Truy cập vào trang quyền cho Tài khoản Google của bạn. (Để chuyển đến trang này trong tương lai, hãy truy cập vào Google.com, sau đó nhấp vào ảnh tài khoản của bạn ở góc trên cùng bên phải màn hình. Tiếp theo, hãy nhấp vào Tài khoản của tôi, sau đó nhấp vào Các ứng dụng và trang web được kết nối trong phần "Đăng nhập và bảo mật", rồi nhấp vào Quản lý ứng dụng.)
Nhấp vào tên của tập lệnh mà bạn muốn thu hồi quyền uỷ quyền, sau đó nhấp vào Xoá ở bên phải, rồi nhấp vào OK trong hộp thoại xuất hiện.
Quyền và các loại tập lệnh
Danh tính người dùng mà một tập lệnh chạy cùng (và do đó, dữ liệu mà tập lệnh có thể truy cập) sẽ thay đổi tuỳ theo trường hợp mà tập lệnh chạy, như minh hoạ trong bảng bên dưới.
Phạm vi uỷ quyền theo cách thủ công cho Trang tính, Tài liệu, Trang trình bày và Biểu mẫu
Nếu đang tạo một tiện ích bổ sung hoặc tập lệnh khác sử dụng Dịch vụ bảng tính, Dịch vụ tài liệu, Dịch vụ Trang trình bày hoặc Dịch vụ biểu mẫu, bạn có thể buộc hộp thoại uỷ quyền chỉ yêu cầu quyền truy cập vào các tệp mà tiện ích bổ sung hoặc tập lệnh được dùng, thay vì tất cả bảng tính, tài liệu hoặc biểu mẫu của người dùng. Để thực hiện việc này, hãy thêm chú thích JsDoc sau đây vào một nhận xét ở cấp tệp:
/***@OnlyCurrentDoc*/
Một chú thích đối lập, @NotOnlyCurrentDoc, sẽ có sẵn nếu tập lệnh của bạn có một thư viện khai báo @OnlyCurrentDoc, nhưng tập lệnh chính thực sự cần quyền truy cập vào nhiều tệp hơn tệp hiện tại.
Vòng đời uỷ quyền cho tiện ích bổ sung
Tiện ích bổ sung cho Google Trang tính, Tài liệu, Trang trình bày và Biểu mẫu thường tuân theo cùng một mô hình uỷ quyền như các tập lệnh được liên kết với một tài liệu. Tuy nhiên, trong một số trường hợp nhất định, các hàm onOpen(e) và onEdit(e) của chúng chạy ở chế độ không uỷ quyền, gây ra một số vấn đề phức tạp khác. Để biết thêm thông tin, hãy xem hướng dẫn về vòng đời uỷ quyền của tiện ích bổ sung.
Giới hạn số người dùng ứng dụng OAuth
Những ứng dụng sử dụng OAuth để truy cập vào dữ liệu người dùng trên Google (bao gồm cả các dự án Apps Script) đều phải tuân theo giới hạn uỷ quyền. Hãy xem bài viết Giới hạn về số lượng người dùng ứng dụng OAuth để biết thông tin chi tiết.
Hành vi xác thực lại bằng Apps Script
Apps Script không thực thi tần suất xác thực lại mà bạn định cấu hình trong phần cài đặt Dịch vụ Google Cloud. Điều này là do Apps Script có thể tự động chạy bằng cách sử dụng các trình kích hoạt. Các trình kích hoạt này hoạt động mà không cần người dùng tương tác trực tiếp. Những lần thực thi tự động này không kích hoạt lời nhắc xác thực lại. Ứng dụng Apps Script sẽ không tự động yêu cầu bạn xác thực lại sau khoảng thời gian bạn đã chỉ định (ví dụ: 12 giờ).
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-19 UTC."],[[["\u003cp\u003eApps Script requires user authorization to access private data from Google services, and requests are based on code analysis.\u003c/p\u003e\n"],["\u003cp\u003eUsers can revoke a script's access to their data through their Google Account permissions settings.\u003c/p\u003e\n"],["\u003cp\u003eA script's access level and the user it runs as depends on the type of script and how it's executed, like standalone, add-on, or web app.\u003c/p\u003e\n"],["\u003cp\u003eFor scripts interacting with Google Workspace files, specific annotations can limit authorization requests to the current file only.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons generally adhere to the authorization model of bound scripts, with exceptions for certain functions and circumstances.\u003c/p\u003e\n"]]],[],null,["Apps Script requires user authorization to access private data from\n[built-in Google services](/apps-script/guides/services) or\n[advanced Google services](/apps-script/guides/services/advanced).\n\nGranting access rights \n\nApps Script determines the authorization scopes (like access your Google Sheets\nfiles or Gmail) automatically, based on a scan of the code. Code that is\ncommented out can still generate an authorization request. If a script needs\nauthorization, you'll see one of the authorization dialogs shown here when it is\nrun.\n\nScripts that you have previously authorized also ask for additional\nauthorization if a code change adds new services. Scripts may not request\nauthorization if you access the script as a web app that runs under\n[the script owner's user identity](/apps-script/execution_web_apps#permissions).\n| **Warning:** Web apps and other scripts that use sensitive scopes are subject to review by Google. Users attempting to authorize such apps may see a warning screen saying the app is *unverified* by Google. See [OAuth client verification](/apps-script/guides/client-verification) for details.\n\nRevoking access rights\n\nTo revoke a script's access to your data, follow these steps:\n\n1. Visit the [permissions](https://security.google.com/settings/security/permissions) page for your Google account. (To navigate to this page in the future, visit [Google.com](https://www.google.com), then click your account picture in the top-right corner of the screen. Next, click **My Account** , then **Connected apps \\& sites** under the \"Sign-in \\& security\" section, and then **Manage Apps**.)\n2. Click the name of the script whose authorization you want to revoke, then click **Remove** on the right, then **OK** in the resulting dialog.\n\nPermissions and types of scripts\n\nThe user identity that a script runs with --- and thus the data it can access ---\nvaries based on the scenario in which the script is run, as shown in the table\nbelow.\n\n| Type of script | Script runs as... |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Standalone](/apps-script/execution_script_editor), [add-on](/workspace/add-ons/overview), or [bound to Docs, Sheets, Slides, or Forms](/apps-script/guides/bound) | User at the keyboard |\n| [Custom function in a spreadsheet](/apps-script/execution_custom_functions) | [Anonymous user](/apps-script/execution_custom_functions#permissions); however, [quota limits](/apps-script/guides/services/quotas) count against user at the keyboard |\n| [Web app](/apps-script/execution_web_apps) or [Google Sites gadget](/apps-script/execution_gadgets) | User at the keyboard or script owner, dependent on [options selected](/apps-script/execution_web_apps#permissions) when deploying the app |\n| [Installable trigger](/apps-script/understanding_triggers#Installable) | User who created the trigger |\n\nManual authorization scopes for Sheets, Docs, Slides, and Forms\n\nIf you're building an [add-on](/workspace/add-ons/overview) or other script that\nuses the [Spreadsheet service](/apps-script/reference/spreadsheet),\n[Document service](/apps-script/reference/document),\n[Slides service](/apps-script/reference/slides), or\n[Forms service](/apps-script/reference/forms), you can force the authorization\ndialog to ask only for access to files in which the add-on or script is used,\nrather than all of a user's spreadsheets, documents, or forms. To do so, include\nthe following [JsDoc](https://jsdoc.app/) annotation in a file-level comment: \n\n /**\n * @OnlyCurrentDoc\n */\n\nAn opposing annotation, `@NotOnlyCurrentDoc`, is available if your script\nincludes a [library](/apps-script/guides/libraries) that declares\n`@OnlyCurrentDoc`, but the master script actually requires access to more than\nthe current file.\n\nAuthorization lifecycle for add-ons\n\n[Add-ons](/workspace/add-ons/overview) for Google Sheets, Docs, Slides, and Forms\ngenerally follow the same authorization model as scripts that are\n[bound](/apps-script/guides/bound) to a document. In certain\ncircumstances, however, their `onOpen(e)` and `onEdit(e)` functions run in a\nno-authorization mode that presents some additional complications. For more\ninformation, see the\n[guide to the add-ons authorization lifecycle](/workspace/add-ons/concepts/addon-authorization#editor_add-on_authorization).\n\nOAuth application user limits\n\nApplications that use OAuth to access Google user data, including Apps\nScript projects, are subject to authorization limits. See\n[OAuth application user limits](https://support.google.com/cloud/answer/9028764)\nfor details."]]