Để thảo luận và đưa ra ý kiến phản hồi về các sản phẩm của chúng tôi, hãy tham gia kênh Discord chính thức của Google Ads trong máy chủ Cộng đồng quảng cáo và đo lường của Google.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hướng dẫn này sẽ hướng dẫn bạn cách thiết lập OAuth2 để truy cập vào API bằng thông tin xác thực của riêng bạn thông qua tài khoản dịch vụ.
Bạn chỉ cần thực hiện các bước này một lần, trừ phi bạn thu hồi hoặc xoá thông tin đăng nhập OAuth2.
Thêm một JSON khoá riêng tư và một email được mạo danh vào cấu hình
Đặt đường dẫn tệp JSON khoá riêng tư và email được mạo danh trong cấu hình của bạn.
Nếu bạn đang sử dụng tệp google-ads.yaml, chuỗi YAML hoặc dict, hãy thêm nội dung sau:
[null,null,["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[[["\u003cp\u003eThis guide explains how to set up OAuth2 for API access using service accounts, a one-time process unless credentials are revoked.\u003c/p\u003e\n"],["\u003cp\u003eThe setup requires a Google Workspace domain and a service account with domain-wide delegation access granted by a super administrator.\u003c/p\u003e\n"],["\u003cp\u003eYou need to generate a service account ID and a JSON file, then add the private key JSON file path and impersonated email to your configuration.\u003c/p\u003e\n"],["\u003cp\u003eConfiguration can be set using a \u003ccode\u003egoogle-ads.yaml\u003c/code\u003e file, YAML string, \u003ccode\u003edict\u003c/code\u003e, or environment variables.\u003c/p\u003e\n"],["\u003cp\u003eThe library prioritizes credentials for desktop or web app flows, so ensure these are not present if you want to use Service Account authentication.\u003c/p\u003e\n"]]],[],null,["# OAuth Service Account Flow\n\nThis guide will walk you through how to set up OAuth2 for API access using your\nown credentials with [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| **Note:** This flow requires a [Google Workspace](//workspace.google.com) domain and a service account that was granted domain-wide delegation access by a super administrator for the domain.\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\nAdd a private key JSON and an impersonated email to configuration\n-----------------------------------------------------------------\n\nSet the private key JSON file path and impersonated email in your configuration.\nIf you're using a `google-ads.yaml` file, YAML string, or `dict`, add the\nfollowing: \n\n json_key_file_path: \u003cvar translate=\"no\"\u003eJSON_KEY_FILE_PATH\u003c/var\u003e\n impersonated_email: \u003cvar translate=\"no\"\u003eIMPERSONATED_EMAIL\u003c/var\u003e\n\nIf you're using environment variables, add the following to your `bash`\nconfiguration or environment: \n\n export GOOGLE_ADS_JSON_KEY_FILE_PATH=\u003cvar translate=\"no\"\u003eJSON_KEY_FILE_PATH\u003c/var\u003e\n export GOOGLE_ADS_IMPERSONATED_EMAIL=\u003cvar translate=\"no\"\u003eIMPERSONATED_EMAIL\u003c/var\u003e\n\n| **Note:** When reading in the configuration, the library first looks for credentials for the OAuth2 desktop or web app flows, and will use them if found. So if you want to use a Service Account authentication, make sure credentials for the other flows are *not* present in your configuration."]]