OAuth 服務帳戶流程
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南將逐步說明如何使用服務帳戶,透過您自己的憑證設定 OAuth2 來存取 API。除非您撤銷或刪除 OAuth2 認證,否則這些步驟只需執行一次。
建立 OAuth2 憑證
按照連結的說明產生服務帳戶 ID 和 *.JSON 檔案,然後返回這個頁面。
設定用戶端程式庫
在設定中設定私密金鑰 JSON 路徑。如果您使用模擬進行驗證,請一併設定要模擬的使用者。
如果您使用 ads.properties
檔案,請新增下列程式碼:
api.googleads.serviceAccountSecretsPath=PRIVATE_KEY_FILE_PATH
# Only add this key if you are using impersonation.
api.googleads.serviceAccountUser=USER_TO_IMPERSONATE
詳情請參閱設定指南。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[[["\u003cp\u003eThis guide explains how to set up OAuth2 for API access using service accounts with your own credentials.\u003c/p\u003e\n"],["\u003cp\u003eThe setup process involves generating a service account ID and a JSON file, and then configuring your client library with the necessary credentials.\u003c/p\u003e\n"],["\u003cp\u003eThis setup needs to be done only once and requires a Google Workspace domain with domain-wide delegation access granted to the service account.\u003c/p\u003e\n"]]],[],null,["# OAuth Service Account Flow\n\nThis guide will walk you through how to setup OAuth2 for API access using your\nown credentials using [service accounts](/google-ads/api/docs/oauth/service-accounts).\nThese steps only need to be done once, unless you revoke or delete your OAuth2\ncredentials.\n\nCreate OAuth2 credentials\n-------------------------\n\n[Generate a **service account ID and a \\*.JSON\nfile**](/google-ads/api/docs/oauth/service-accounts#service_account_access_setup) by\nfollowing the linked instructions, then come back to this page.\n\nSet up client library\n---------------------\n\nSet the private key JSON path in your configuration. If you're [authenticating\nusing impersonation](/google-ads/api/docs/oauth/service-accounts#impersonation), also set the\nuser to impersonate.\n\nIf you're using an `ads.properties` file, add the following: \n\n api.googleads.serviceAccountSecretsPath=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-s\"\u003ePRIVATE_KEY_FILE_PATH\u003c/span\u003e\u003c/var\u003e\n # Only add this key if you are using impersonation.\n api.googleads.serviceAccountUser=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-s\"\u003eUSER_TO_IMPERSONATE\u003c/span\u003e\u003c/var\u003e\n\nSee the [configuration guide](/google-ads/api/docs/client-libs/java/config-file) for\nadditional details."]]