啟用指令碼授權和存取權
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
視目標而定,Apps Script API 需要不同類型的授權:
- 在應用程式中使用 Apps Script API。
- 允許其他應用程式管理您的指令碼專案資料或部署作業。
如要在應用程式中使用 Apps Script API,請務必在應用程式的 Google Cloud 專案中啟用該 API。
這樣一來,您就能建立 OAuth 憑證,讓應用程式使用者授權。
如要允許第三方應用程式管理指令碼專案的內容或部署作業,請授予指令碼專案存取權。
在應用程式中使用 Apps Script API
如要在應用程式中使用 Apps Script API,請務必在應用程式的 GCP 專案中啟用 Apps Script API。啟用 Apps Script API 後,您就可以建立 OAuth 憑證,並下載用戶端 ID 和密鑰,以便納入應用程式。您也可以在 Google Cloud 控制台監控 API 用量。
您可以使用這個精靈,在 API 控制台中建立或選取 Google Cloud 專案,並自動啟用 API。或者,您也可以開啟控制台的「管理資源」頁面,選取專案,然後使用專案的「API 和服務」資訊主頁,手動搜尋並新增 Apps Script API。啟用 API 後,您可以在「API 和服務」>「憑證」面板中,為應用程式建立 OAuth 憑證、用戶端 ID 和用戶端密鑰。
Apps Script API 快速入門導覽課程會逐步說明啟用 API 和設定應用程式授權的整個過程。
授予第三方應用程式存取指令碼專案的權限
應用程式可透過 Apps Script API 建立及修改指令碼和部署作業。如果您授權惡意第三方應用程式,該應用程式可能會建立更多惡意指令碼,或修改現有指令碼的行為,導致情況惡化。
為降低這項風險,Apps Script API 預設無法存取指令碼專案。您必須明確授予 API 存取權,才能使用任何建立或修改指令碼或部署作業的應用程式。授予 API 存取指令碼的權限後,您授權的應用程式就能使用 API 管理指令碼專案。
如果嘗試在未先授予 API 存取權的情況下執行受影響的應用程式,就會發生錯誤。授權應用程式後,就會發生這個錯誤。
您可以使用 Apps Script 資訊主頁,授予 Apps Script API 存取指令碼專案的權限。您也可以隨時透過資訊主頁撤銷這項存取權。授予 API 存取權時,您是為「所有」應用程式授予存取權。但仍須授權個別應用程式。
授予存取權前,請務必瞭解允許應用程式修改指令碼的風險。請勿授權任何您懷疑是惡意的應用程式。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThe Apps Script API requires enabling in your Google Cloud project to use it within your own application, allowing you to create OAuth credentials for user authorization.\u003c/p\u003e\n"],["\u003cp\u003eTo allow external applications to manage your script projects, you must grant access to them through the Apps Script dashboard, understanding the potential security risks involved.\u003c/p\u003e\n"],["\u003cp\u003eGranting access enables third-party applications to create, modify, and deploy your Apps Script projects but does not automatically authorize them; individual authorization is still required.\u003c/p\u003e\n"],["\u003cp\u003eExecuting Apps Script functions through the API does not necessitate granting access to your script projects.\u003c/p\u003e\n"]]],[],null,["# Enabling script authorization and access\n\nThe Apps Script API requires different types of authorizations depending on\nyour goal:\n\n- Use the Apps Script API in your app.\n- Allow other applications to manage your script project data or deployments.\n\nIf you need to use the Apps Script API in your application, you must *enable*\nthe API in the application's\n[Google Cloud project](https://cloud.google.com/apis/docs/enable-disable-apis#enable_an_api).\nThis allows you to create OAuth credentials so that users of the application\ncan authorize it.\n\nIf you want to let third-party applications manage the content or deployment\nof your script projects, you must *grant access* to your script projects.\n\nUsing the Apps Script API in your app\n-------------------------------------\n\nIf you want to use the Apps Script API inside your app, you must enable\nthe Apps Script API in your application's GCP project. After\nenabling the Apps Script API, you can create OAuth credentials and download\nthe client ID and secret to include in your application. You can also\nmonitor the API usage in the\n[Google Cloud console](https://console.cloud.google.com/).\n\nYou can use\n[this wizard](https://console.developers.google.com/start/api?id=script)\nto create or select a Google Cloud project in the API console and automatically enable\nthe API. Alternatively, you can\n[open the console's **Manage Resources** page](https://console.cloud.google.com/cloud-resource-manager),\nselect a project, then search for and add the Apps Script API manually using the\nproject's **APIs \\& services** dashboard. Once you've enabled the API, you can\ncreate OAuth credentials, client IDs, and client secrets for your applications\nin the **APIs \\& services \\\u003e Credentials** panel.\n\nThe [Apps Script API quickstarts](/apps-script/api/quickstart/python#step_1_turn_on_the_api_name)\nprovide a step-by-step look at the whole process of enabling the API and\nsetting up authorization for an application.\n\nGranting third-party applications access to your script projects\n----------------------------------------------------------------\n\nThe Apps Script API can allow applications to create and modify your scripts\nand their [deployments](/apps-script/concepts/deployments). This can lead to\na bad situation if you authorize a malicious third-party application which\nthen proceeds to create more malicious scripts or modify the behavior of\nscripts you already have.\n\nTo help reduce this risk, the Apps Script API cannot access your script\nprojects by default. You must explicitly grant the API access before you can use\nany application that creates or modifies scripts or deployments. Once you've\ngranted the API access to your scripts, applications you authorize can use the\nAPI to manage your script projects.\n\nAn error results if you attempt to run an affected application without\nfirst granting the API access. This error occurs after you authorize the\napplication.\n| **Note:** Applications can use the Apps Script API to [execute Apps Script functions](/apps-script/api/reference/rest/v1/scripts/run). These API requests do not require granting access to your script projects.\n\nYou can grant the Apps Script API access to your script projects using the\n[Apps Script dashboard](/apps-script/guides/dashboard#settings). You can also\nuse the dashboard to revoke this access at any time. When you grant the\nAPI access, you are doing so for *all* applications. Individual applications\nstill need to be authorized, however.\n\nBefore you grant access, be sure you understand that there is a risk involved\nin allowing applications to modify your scripts. Never authorize any application\nthat you suspect is malicious."]]