开始使用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档面向希望使用 AdSense Management API 获取其 AdSense 帐号相关信息的开发者。本文档假定您熟悉 Web 编程的概念和 Web 数据格式。
前期准备
获取 AdSense 账号
注册或登录您的 AdSense 账号即可开始。
熟悉 AdSense
如果您不熟悉 AdSense 概念,请在开始编码之前阅读 AdSense 介绍信息,并练习使用 AdSense 界面。
选择您的客户端库
在客户端库和示例页面中,您可以找到关于可用库和示例的信息。点击与您所选语言对应的标签页,然后点击相应链接下载源代码。
客户端库会为您处理以下事宜:
- 身份验证
- 服务发现
- 构建向 API 发出的请求
- 响应解析
请阅读相关说明,了解如何安装和配置您选择的客户端库(通常位于代码库根目录下的 README 文件中)。
如果您的实现有特殊需求(例如使用不受支持的语言),您可以向 API 发出直接请求,而不是使用客户端库。
注册应用
要使用 AdSense Management API,您必须通过创建项目并生成客户端 ID 来注册您开发的应用。
注册您的应用
使用您刚刚创建的新凭据,修改客户端库项目的配置文件。如需了解详情,请参阅客户端库文档。
注意:用于注册的 Google 帐号应该是您的开发者帐号,也就是您希望应用的用户将其视为应用开发者的帐号。此帐号无需与 AdSense 登录信息相关联,因为用户在使用该应用时将获得对自己帐号的访问权限。
快速入门教程
请按照以下步骤发出第一个请求。请注意,根据您所使用的库或语言,这些步骤可能会略有不同:
- 使用相应示例从 AdSense 帐号中获取广告客户列表。此请求会启动一个一次性过程,在此期间,AdSense 用户对您的项目进行身份验证和授权。
广告客户代表 AdSense 帐号与 AdSense 产品(如内容广告或搜索广告)之间的关联。一个 AdSense 帐号可以有一个或多个广告客户。
- 对于 Web 应用,用户将被重定向到他们可以选择授予访问权限的网站。获得授权后,他们将被重定向到 Google API 控制台中定义的回调网址。
- 安装版应用的工作原理与之类似。客户端库将尝试打开浏览器窗口并使用授权代码。对于 Android、Chrome 和 iOS 应用,此方法因平台而异。
- 使用适用于
reports.generate
的 Google API Explorer 请求以下报告:
date_range: YESTERDAY
dimensions: DATE
metrics: ESTIMATED_EARNINGS
您可以通过报告深入了解自己的收入,还能了解影响这些收入的因素。通过使用渠道,可以对整个帐号运行预测,也可以对广告单元的子集运行。
- 尝试从您的应用请求相同的报告。
- 您可以按广告单元过滤报告。使用
adunits.list
获取广告单元列表。请注意,您需要提供广告客户 ID(可在第 1 步中获取)。选择广告单元后,请在 reports.generate
的 filter 参数中使用其 ID:广告单元是用户为广告配置的占位符,用于定义所展示的广告的一些属性(如尺寸和形状)。
date_range: YESTERDAY
dimensions: DATE
metrics: ESTIMATED_EARNINGS
filter: AD_UNIT_ID==ca-pub-123456789:987654321
- 请尝试按自定义渠道或网址渠道进行过滤,或混合使用多个过滤条件。
通过渠道,您可以跟踪广告单元子集的广告效果。渠道有两种类型:网址渠道和自定义渠道。前者可以帮助您跟踪特定网页或网域的效果,而后者可以帮助您跟踪用户选择的特定广告单元组的效果。
在了解参考文档中的其他可用调用和资源后,您可以开始实现该功能。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eStarts ADH import of a specified BigQuery table containing a quarterly brand lift benchmark report, triggered by the customer.\u003c/p\u003e\n"],["\u003cp\u003eRequires specifying the year, quarter, and source BigQuery table in the request body.\u003c/p\u003e\n"],["\u003cp\u003eUses POST request to \u003ccode\u003ehttps://adsdatahub.googleapis.com/v1/{customer=customers/*}:submitBrandLiftBenchmark\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eNeeds \u003ccode\u003ehttps://www.googleapis.com/auth/adsdatahub\u003c/code\u003e authorization scope.\u003c/p\u003e\n"],["\u003cp\u003eReturns an Operation object upon successful submission.\u003c/p\u003e\n"]]],["To use the AdSense Management API, first, obtain an AdSense account and familiarize yourself with it. Select a client library or make direct API requests. Register your application to get a Client ID, and configure your project with the credentials. Retrieve a list of ad clients, then generate reports using the API explorer or your application. Filter reports by ad units or channels, and explore the API reference documentation to start implementing your code.\n"],null,["# Get Started\n\nThis document is for developers who want to use the AdSense Management API to get\ninformation about their AdSense account. This document assumes that you're\nfamiliar with web programming concepts and web data formats.\n\nBefore you start\n----------------\n\n### Get an AdSense account\n\nSign up or sign in to your [AdSense\naccount](//adsense.google.com/) to get started.\n\n### Get familiar with AdSense\n\nIf you're not familiar with AdSense concepts read the [introductory information on AdSense](//support.google.com/adsense)\nand experiment with the [AdSense UI](//adsense.google.com/)\nbefore starting to code.\n\n### Choose your client library\n\nIn the [Client Libraries and Samples\npage](/adsense/management/libraries), you'll find information on the available libraries and samples. Click\nthe tab for your chosen language and follow the links to download the source.\nThe client libraries handle the following for you:\n\n- authentication\n- discovery of services\n- building the requests to the API\n- response parsing\n\nRead the instructions to install and configure your chosen client library,\ntypically found in the README file in the root directory of the repository.\n\nIf your implementation has special needs, such as using an unsupported\nlanguage, you can [make direct\nrequests](/adsense/management/direct_requests) to the API instead of using a client library.\n\nRegister your application\n-------------------------\n\nTo use the AdSense Management API you must register the application you're developing\nby creating a project and generating a Client ID.\nRegister your app\n\nEdit the configuration files for your client library project with the new\ncredentials you just created. Check the client library documentation for more\ndetails.\n\n**Note:** The Google Account used for registration should be\nyour **developer** account, that is, the account that you want users of your\napplication to see as the developer of the application. **This account does\nnot need to be tied to an AdSense login**, as users will be granting access\nto their own accounts while using the application.\n\nQuick start tutorial\n--------------------\n\nFollow the steps below to make your first requests, note that these steps\nmay vary slightly depending on the library or language you are using:\n\n1. Use the appropriate sample to retrieve a list of ad clients from an AdSense account. This request initiates a one-time process in which the AdSense user authenticates and authorizes your project. **Ad clients** represent an association between an\n AdSense account and an AdSense product, such as Content Ads or Search Ads.\n An AdSense account can have one or multiple ad clients.\n\n 1. For **web applications**, users will be redirected to a site where they can choose to grant access. Once authorized, they will be redirected to the callback URL defined in the Google API Console.\n 2. **Installed applications** work similarly. The client library will try to open a browser window and use an authorization code. For Android, Chrome and iOS applications this method is platform-specific.\n2. Use the [Google APIs explorer for\n `reports.generate`](/adsense/management/reference/rest/v2/accounts.reports/generate) to request the following report:\n - `date_range: YESTERDAY`\n - `dimensions: DATE`\n - `metrics: ESTIMATED_EARNINGS`\n\n **Reports** give you insight into what you're earning,\n as well as what's having an impact on those earnings. They can be run on\n an entire account or on a subset of ad units, through the use of\n channels.\n3. Try to request the same report from your application.\n4. You can filter the reports by ad units. Fetch the list of ad units using [adunits.list](/adsense/management/reference/rest/v2/accounts.adclients.adunits/list). Note that an ad client ID is needed (get it from step 1). After you choose an ad unit, use its ID in the [filter](/adsense/management/reporting/filtering) parameter for `reports.generate`:\n\n **Ad Units** are user-configured placeholders for ads,\n that define some properties for the ads being shown (such as size and\n shape).\n - `date_range: YESTERDAY`\n - `dimensions: DATE`\n - `metrics: ESTIMATED_EARNINGS`\n - `filter: AD_UNIT_ID==ca-pub-123456789:987654321`\n5. Try filtering by custom or URL channels or mixing multiple filters. **Channels** are tools that let you track the\n performance of a subset of your ad units. There are two types of channels:\n URL and custom. The former lets you track performance across a specific\n page or domain, whereas the latter help you track performance on specific\n user-selected groups of ad units.\n\nYou are ready to start your implementation by exploring the rest of the\navailable calls and resources in the [reference\ndocumentation](/adsense/management/reference/rest)."]]