调用 Google Ads API 时,您需要 OAuth 2.0 应用凭据和开发者令牌。如果您使用 Google Ads 经理账号进行 API 调用,还需要在每个请求中指定 login-customer-id 标头。本页面介绍了如何设置这些值,并记录了使用 REST 接口时发送和接收的几个额外的特定于 API 的 HTTP 标头。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-05。"],[[["\u003cp\u003eThe Google Ads API requires OAuth 2.0 application credentials and a developer token for authentication, along with a \u003ccode\u003elogin-customer-id\u003c/code\u003e header for manager account access.\u003c/p\u003e\n"],["\u003cp\u003eYou can generate new access tokens using your client ID, client secret, and refresh token via the provided \u003ccode\u003ecurl\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eInclude the developer token in the \u003ccode\u003edeveloper-token\u003c/code\u003e header and the access token in the \u003ccode\u003eAuthorization\u003c/code\u003e header for API calls.\u003c/p\u003e\n"],["\u003cp\u003eManager accounts accessing client accounts need to provide the \u003ccode\u003elogin-customer-id\u003c/code\u003e header, representing the manager's customer ID.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003erequest-id\u003c/code\u003e header in API responses helps in debugging and troubleshooting by uniquely identifying each request.\u003c/p\u003e\n"]]],[],null,["# Authorization and HTTP Headers\n\nondemand_video\n[Video: Authentication](/google-ads/api/videos/catalog/working-with-rest-2)\n\nYou need both OAuth 2.0 application credentials and a [developer\ntoken](#developer_token) when calling the Google Ads API. If you're making API calls\nwith a Google Ads manager account, you also need to specify a `login-customer-id`\nheader with each request. This page describes how to set these values and\ndocuments several additional API-specific HTTP headers that are sent and\nreceived when using the REST interface.\n\nOAuth 2.0 credentials\n---------------------\n\nThe Google Ads API uses *application credentials* for identifying and authorizing API\nrequests. Both OAuth 2.0 clients and [service\naccounts](/google-ads/api/docs/oauth/service-accounts) can be configured. For more details\nabout configuring client-side authorization, see [OAuth2 in the\nGoogle Ads API](/google-ads/api/docs/oauth/overview).\n\nIf you are new to Google APIs, you can use\n[oauth2l](//github.com/google/oauth2l) or the [OAuth 2.0\nPlayground](//developers.google.com/oauthplayground/) to experiment with\napplication credentials and the Google Ads API before writing the code for your\napp.\n\n### Using desktop or web app flows\n\nFollow the steps to [configure a Google API Console project for the\nGoogle Ads API](/google-ads/api/docs/oauth/cloud-project). Record the *client ID* and\n*client secret*, then come back to this page.\n\nOnce you've created an OAuth client, follow the [desktop app flow\ninstructions](/identity/protocols/oauth2/native-app#obtainingaccesstokens) or\nthe [web app flow\ninstructions](/identity/protocols/oauth2/web-server#obtainingaccesstokens) to\ngenerate a *refresh token* and an *access token*.\n\n### Using service accounts\n\nFollow the common instructions in the [Service\nAccounts](/google-ads/api/docs/oauth/service-accounts#setting_up_service_account_access)\nguide to set up service account access for the Google Ads API.\n\nOnce you've set up a service account to access your Google Ads account, follow the\n[Using OAuth 2.0 for Server to Server\nApplications](/identity/protocols/oauth2/service-account#authorizingrequests)\nguide, making sure to select the `HTTP/REST` tab. The `scope` to use for Google Ads API\naccess is `https://www.googleapis.com/auth/adwords`.\n\n### Generating new access tokens\n\nOnce you have a *client ID* , *client secret* , and *refresh token* , you can\ngenerate a new access token for use in API calls with the\n[`curl`](https://curl.haxx.se/) command line tool:\n**Note:** The version `v3` in the OAuth endpoint URL is unrelated to the Google Ads API version and should not change when migrating to newer versions of Google Ads API. \n\n curl \\\n --data \"grant_type=refresh_token\" \\\n --data \"client_id=\u003cvar translate=\"no\"\u003eCLIENT_ID\u003c/var\u003e\" \\\n --data \"client_secret=\u003cvar translate=\"no\"\u003eCLIENT_SECRET\u003c/var\u003e\" \\\n --data \"refresh_token=\u003cvar translate=\"no\"\u003eREFRESH_TOKEN\u003c/var\u003e\" \\\n https://www.googleapis.com/oauth2/v3/token\n\nYou then use the *access token* returned by the curl request in the\n`Authorization` HTTP header of every API call to the Google Ads API: \n\n GET /v21/customers:listAccessibleCustomers HTTP/1.1\n Host: googleads.googleapis.com\n Authorization: Bearer \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e\n developer-token: \u003cvar translate=\"no\"\u003eDEVELOPER_TOKEN\u003c/var\u003e\n\nRequest headers\n---------------\n\n### Developer token\n\nThe Google Ads API also requires a *developer token* in order to make calls to\nthe API. You can apply for a token for your manager account directly from the\nGoogle Ads UI. For more details about getting set up with a developer token, see\n[Obtain Your Developer Token](/google-ads/api/docs/get-started/dev-token).\n\nYou need to include your developer token value in the `developer-token` HTTP\nheader of every API call to the Google Ads API: \n\n GET /v21/customers:listAccessibleCustomers HTTP/1.1\n Host: googleads.googleapis.com\n Authorization: Bearer \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e\n developer-token: \u003cvar translate=\"no\"\u003eDEVELOPER_TOKEN\u003c/var\u003e\n\n### Login customer ID\n\nFor Google Ads API calls made by a manager to a client account (that is, when\nlogging in as a manager to make API calls to one of its client accounts), you\nalso need to supply the `login-customer-id` HTTP header. This value represents\nthe Google Ads customer ID of the manager making the API call.\n\nIncluding this header is equivalent to choosing an account in the Google Ads UI\nafter signing in or clicking on your profile image at the top-right corner of\nthe page. When specifying the customer ID, be sure to remove any hyphens (---),\nfor example: `1234567890`, not `123-456-7890`. \n\n GET /v21/customers:listAccessibleCustomers HTTP/1.1\n Host: googleads.googleapis.com\n Authorization: Bearer \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e\n developer-token: \u003cvar translate=\"no\"\u003eDEVELOPER_TOKEN\u003c/var\u003e\n login-customer-id: \u003cvar translate=\"no\"\u003eMANAGER_CUSTOMER_ID\u003c/var\u003e\n\n| **Key Point:** If you're not authorizing as a manager account; in other words, if your OAuth 2.0 credentials are for a user of the target Google Ads *client* account directly, you don't need to supply a `login-customer-id` header.\n\n### Linked customer ID\n\nThis header is only used by [third-party app analytics providers when\nuploading conversions to a linked Google Ads\naccount](//support.google.com/google-ads/answer/7365001). See the\n[API Call Structure guide](/google-ads/api/docs/concepts/call-structure#linked-customer-id)\nfor more details. \n\n ...\n Authorization: Bearer \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e\n developer-token: \u003cvar translate=\"no\"\u003eDEVELOPER_TOKEN\u003c/var\u003e\n login-customer-id: \u003cvar translate=\"no\"\u003eMANAGER_CUSTOMER_ID\u003c/var\u003e\n linked-customer-id: \u003cvar translate=\"no\"\u003eLINKED_CUSTOMER_ID\u003c/var\u003e\n\nResponse headers\n----------------\n\nThe following headers are returned in HTTP responses from the API.\n\n### Request ID\n\nThe `request-id` is a string that uniquely identifies the API request. When\ndebugging or troubleshooting problems with specific API calls, the `request-id`\nis an important identifier to have handy when contacting Google developer\nsupport. \n\n request-id: 2a5Cj89VV7CNhya1DZjjrC"]]