借助 AdMob API,您可以以编程方式查看中介广告来源。如需了解更多信息,请参阅 accounts.adSources.list。
使用 Curl 发出请求
加载Secret 文件并生成授权凭据。
第一次执行此步骤时,系统会在浏览器中提示您接受授权。接受之前,请务必使用可访问 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 替换为您的发布商 ID,即可获取 AdMob 广告来源信息。请参阅有关如何查找发布商 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", } ] }