這則註解會告知 Apps Script 將編輯器檔案範圍縮小為 currentonly。舉例來說,如果您在 Google 試算表外掛程式指令碼專案檔案中新增這則註解,即表示外掛程式只需要在目前開啟的試算表中運作的權限,不需要存取使用者在 Google 雲端硬碟中的任何其他試算表。反之,如果 Google 試算表外掛程式需要讀取或寫入使用者目前未開啟的試算表資料,則不應使用這項註解。
[null,null,["上次更新時間:2025-08-01 (世界標準時間)。"],[[["\u003cp\u003eUsers must grant authorization to add-ons before they can access data or act on their behalf, which involves a prompt detailing the requested permissions.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons define the specific permissions they need using OAuth scopes, declared in the manifest file as URL strings.\u003c/p\u003e\n"],["\u003cp\u003eFor published add-ons, explicitly define the necessary OAuth scopes in the manifest to ensure the least permissive access and comply with add-on review guidelines.\u003c/p\u003e\n"],["\u003cp\u003eApps Script automatically detects and sets required scopes, but explicit control is recommended for published add-ons to limit permissions and enhance security.\u003c/p\u003e\n"],["\u003cp\u003eSensitive or restricted scopes may necessitate OAuth client verification before publishing an add-on.\u003c/p\u003e\n"]]],["Add-ons require user authorization to access data, initiated through an authorization prompt presenting the requested permissions (OAuth scopes). These scopes, defined as URL strings in the add-on's manifest, detail what the add-on can do (e.g., read emails). While Apps Script auto-detects needed scopes, published add-ons must set explicit, least-permissive scopes in their manifest. Restricted scopes are subject to additional rules and should be avoided if possible. Users can review and manage permissions granted to their add-ons.\n"],null,["# Authorization scopes for Editor add-ons\n\nUsers must authorize add-ons and other applications that access their data\nor act on their behalf. When a user runs an add-on for the first time, the\nadd-on UI presents an authorization prompt to start the authorization flow.\n\nDuring this flow, the prompt tells the user what the application wants\npermission to do. For example, an add-on might want permission to read a\nuser's email message or create events in their calendar. The add-on's script\nproject defines these individual permissions as *OAuth scopes*.\n\nYou declare scopes in your [manifest](/workspace/add-ons/concepts/editor-manifests)\nusing URL strings. During the authorization flow, Apps Script presents a\nhuman-readable description of the scope to the user. For\nexample, your add-on might use the \"Read current document\" scope, which\nis written in your manifest as\n`https://www.googleapis.com/auth/documents.currentonly`. During the\nauthorization flow, an add-on with this scope asks the user to allow theadd-on\nto: **View and manage documents that this application has been installed in.**\n| **Note:** The `currentonly` scope is only available within Apps Script Services. This does not include Apps Script [Advanced Services](/apps-script/guides/services/advanced) or direct calls to Google Workspace APIs.\n\n\u003cbr /\u003e\n\n| **Note:** The scopes Apps Script uses for its various services overlap with the scopes used by the related API. For example, Apps Script's [Calendar service](/apps-script/reference/calendar) uses many of the same scopes as the [Calendar API](/workspace/calendar). You can look up the scopes that particular Apps Script service methods require in the Apps Script [reference documentation](/apps-script/reference).\n\nViewing scopes\n--------------\n\nYou can see the scopes your script project currently requires by doing the\nfollowing:\n\n1. Open the script project.\n2. At the left, click **Overview** info_outline.\n3. View the scopes under \"Project OAuth Scopes.\"\n\nYou can also view the script project's current scopes in the project manifest,\nunder the [`oauthScopes`](/apps-script/manifest#Manifest.FIELDS.oauthScopes)\nfield, but only if you have set those scopes [explicitly](#setting_explicit_scopes).\n\nSetting explicit scopes\n-----------------------\n\nApps Script automatically determines what scopes a script needs by scanning\nits code for function calls that require them. For most scripts this is\nsufficient and saves you time, but for published add-ons you should exercise\nmore direct control of the scopes.\n\nFor example, Apps Script might give an add-on script project the very permissive\nscope `https://mail.google.com` by default. When a user authorizes a script\nproject with this scope, the project is granted full access to the user's Gmail\naccount. For published add-ons, you **must** replace this scope with a more\nlimited set that cover the add-ons's needs and no more.\n| **Warning:** Always use the least permissive scope set possible. To protect user information, add-ons and other published applications should *never* ask for more scope permissions then they absolutely need. The scopes your add-on requires are examined during the publication [add-on review](/workspace/marketplace/about-app-review) process; if the add-on uses scopes that are too broad it can't pass review.\n\nYou can explicitly set the scopes your script project uses by editing\nits [manifest](/workspace/add-ons/concepts/editor-manifests) file. The manifest field\n[`oauthScopes`](/apps-script/manifest#Manifest.FIELDS.oauthScopes) is an array\nof all scopes used by the add-on. To set your project's scopes, do the\nfollowing:\n\n1. [View the scopes your add-on currently uses](#viewing_scopes). Determine what changes need to be made, such as using a narrower scope.\n2. [Open your add-on's manifest file](/workspace/add-ons/concepts/editor-manifests#editing_a_manifest).\n3. Locate the top-level field labeled `oauthScopes`. If it is not present, you can add it.\n4. The [`oauthScopes`](/apps-script/manifest#Manifest.FIELDS.oauthScopes)\n field specifies an array of strings. To set the scopes\n your project uses, replace the contents of this array with the scopes you\n want it to use.\n For example, for an Editor add-on that extends Sheets\n you might have the following:\n\n {\n ...\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/script.container.ui\",\n \"https://www.googleapis.com/auth/spreadsheets\"\n ],\n ...\n }\n\n \u003cbr /\u003e\n\n5. Save the manifest file changes.\n\nOAuth verification\n------------------\n\nUsing certain sensitive OAuth scopes may require that your add-on go through\n[OAuth client verification](/apps-script/guides/client-verification)\nbefore you can publish it. For more information, see the following guides:\n\n- [OAuth client verification for Apps Script](/apps-script/guides/client-verification)\n- [Unverified apps](https://support.google.com/cloud/answer/7454865)\n- [OAuth verification FAQ](https://support.google.com/cloud/answer/9110914)\n- [Google APIs Service: User Data Policy](/terms/api-services-user-data-policy)\n\nRestricted scopes\n-----------------\n\nCertain scopes are *restricted* and subject to additional rules that help\nprotect user data. If you intend to publish a Gmail or Editor add-on that uses\none or more restricted scopes, the add-on must comply with all the specified\nrestrictions before it can be published.\n\nReview the [full list of restricted scopes](https://support.google.com/cloud/answer/9110914#restricted-scopes)\nbefore you attempt to publish. If your add-on uses any of them, you must comply\nwith the\n[Additional requirements for specific API scopes](/terms/api-services-user-data-policy#additional-requirements-for-specific-api-scopes)\nprior to publishing.\n| **Note:** Avoid using restricted scopes in your add-on if you can---it is easier to pass add-on review for public publication if you don't use them. You can use restricted scopes freely for non-public add-ons.\n\nThe [Google Workspace Developer Tools extension](https://marketplace.visualstudio.com/items?itemName=google-workspace.google-workspace-developer-tools) for Visual Studio Code provides diagnostic information for all scopes including the scope's description and whether it is sensitive or restricted.\n\nEditor add-on scopes\n--------------------\n\nWhen you build an Editor add-on, the required scopes are determined by the\nApps Script service and methods the add-on code uses. For example, a Sheets\nadd-on might need the\n`https://www.googleapis.com/auth/spreadsheets.readonly` scope in order to read\ninformation from different Google Sheets.\n\nApps Script automatically determines the scopes required by the services you\nuse as you add code to your script project. For Editor add-ons, you can often\njust rely on this automatic scope collection instead of determining the scopes\nyourself and setting them explicitly.\n\nIf you are not setting your scopes explicitly and your Editor add-on only ever\nreads or writes to the open editor file, add the following comment to one of\nyour script project files: \n\n /**\n * @OnlyCurrentDoc\n */\n\nThis comment tells Apps Script to narrow the editor file scopes it sets to\n`currentonly`. For example, if you add this comment to a Google Sheets add-on script\nproject file, you are specifying that the add-on only needs permission to\noperate on the currently open Sheet, and not any other Sheets the user might\nhave in Google Drive. Conversely, you shouldn't use this comment if your Sheets\nadd-on needs to read or write data in a Sheet the user currently hasn't opened.\n| **Note:** The `currentonly` scope is only available within Apps Script Services. This does not include Apps Script [Advanced Services](/apps-script/guides/services/advanced) or direct calls to Google Workspace APIs."]]