广告来源
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 AdMob API,您可以查看中介广告来源
以编程方式请参阅
accounts.adSources.list
,了解更多信息。
使用 Curl 发出请求
加载客户端密钥文件并生成授权
凭据。
首次执行此步骤时,系统会提示您接受
授权提示。在接受之前,请确保您已
使用有权访问 AdMob API 的 Google 账号登录。您的
应用获得授权后,才能代表哪个账号访问数据
目前已登录。
对于身份验证和授权,我们建议使用
oauth2l,一种用于
与 Google OAuth 2.0 搭配使用安装 oauth2l 并运行
命令,将 path_to_credentials_json 替换为路径
保存到您的 credentials.json
文件中。
云应用首次运行时,此命令将引导您逐步完成
OAuth 2.0 授权流程。后续运行会刷新令牌
。
oauth2l header --json path_to_credentials_json --scope admob.readonly
列出广告来源。
替换 pub-XXXXXXXXXXXXXXXX,获取 AdMob 广告来源信息
替换为您的发布商 ID。请参阅
说明,了解如何查找
您的发布商 ID
curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources \
-H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
示例响应:
{
"adSources": [
{
"name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855",
"adSourceId": "5450213213286189855",
"title": "AdMob Network",
}
]
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe AdMob API allows programmatic access to view mediation ad sources.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication and authorization are handled using OAuth 2.0, preferably through the \u003ccode\u003eoauth2l\u003c/code\u003e tool.\u003c/p\u003e\n"],["\u003cp\u003eTo list ad sources, a request using \u003ccode\u003ecurl\u003c/code\u003e is made to the AdMob API endpoint, including your publisher ID and authorization credentials.\u003c/p\u003e\n"]]],[],null,["# Ad Sources\n\nThe AdMob API lets you view [mediation ad sources](/admob/api/v1/ad-sources-reference)\nprogrammatically. See\n[`accounts.adSources.list`](/admob/api/reference/rest/v1beta/accounts.adSources/list)\nfor additional information. \n\n### Request using Curl\n\n1. Load the [client secrets file](https://console.cloud.google.com/apis/credentials) and generate authorization\n credentials.\n\n The first time you perform this step you'll be asked to accept an\n authorization prompt in your browser. Before accepting, make sure you're\n signed in with a Google Account that has access to the AdMob API. Your\n app will be authorized to access data on behalf of whichever account is\n currently signed in.\n\n For authentication and authorization, we recommend using\n [oauth2l](//github.com/google/oauth2l), a simple command-line tool for\n working with Google OAuth 2.0. Install oauth2l and run the\n command below, replacing \u003cvar translate=\"no\"\u003epath_to_credentials_json\u003c/var\u003e with a path\n to a `credentials.json` file that you download when registering your\n cloud application. For the first run, the command walks you through the\n OAuth 2.0 authorization flow. Subsequent runs refresh the token\n automatically. \n\n ```\n oauth2l header --json path_to_credentials_json --scope admob.readonly\n ```\n2. List ad sources.\n\n Get AdMob ad source information by replacing \u003cvar translate=\"no\"\u003epub-XXXXXXXXXXXXXXXX\u003c/var\u003e\n with your publisher ID. See the\n [instructions](//support.google.com/admob/answer/2784578) on how to find\n your publisher ID. \n\n ```\n curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources \\\n -H \"$(oauth2l header --json path_to_credentials_json --scope admob.readonly)\"\n ```\n\n Sample response: \n\n ```text\n {\n \"adSources\": [\n {\n \"name\": \"accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855\",\n \"adSourceId\": \"5450213213286189855\",\n \"title\": \"AdMob Network\",\n }\n ]\n }\n ```"]]