ID
大多数 Google Ads 实体都会公开一个 getId()
方法,用于返回其标识符。虽然在大多数情况下并非绝对必要,但在以下情况下,ID 可能会派上用场:
- 使用报告
- ID 提供了一种将报告行与实际 Google Ads 实体相关联的好方法。
- 维护与外部数据存储之间的映射
- 您可能已在自己的数据库中存储了基于 ID 的信息。
- 寻求性能方面的提升
通过 ID 来抓取通常要比其他方法更快。获取单个实体的代码也更简单:
let campaigns = AdsApp.campaigns()
.withIds([678678])
.get();
// vs.
let campaigns = AdsApp.campaigns()
.withCondition("Name='My Campaign'")
.get();
唯一性
广告系列 ID 和广告组 ID 是唯一的:两个广告系列或广告组永远不会共用同一个 ID。不过,广告和关键字具有复合 ID:关键字的唯一标识符是其广告组 ID 和关键字 ID 的组合。同样,广告的唯一标识符是其广告组 ID 和广告 ID 的组合。这会影响 selector.withIds()
的调用方式。
对于广告系列和广告组,selector.withIds()
需要一个数字数组:
let ids = [123123, 234234, 345345];
let campaignSelector = AdsApp.campaigns().withIds(ids);
不过,对于广告和关键字,selector.withIds()
需要一个包含双元素数组的数组,其中第一个元素是广告组 ID。以下代码段从广告组中检索了三个关键字:
let adGroupId = 123123;
let keywordSelector = AdsApp.keywords().withIds([
[adGroupId, 234234],
[adGroupId, 345345],
[adGroupId, 456456]
]);
在提取广告时,也适用相同的结构。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-13。
[null,null,["最后更新时间 (UTC):2025-07-13。"],[[["Most Google Ads entities have a `getId()` method, which returns a unique identifier that can be useful for linking data, improving performance, and referencing external databases."],["When working with reports, IDs can connect report rows to specific Google Ads entities."],["Fetching entities by ID is often faster than using other methods like filtering by name."],["Campaign and ad group IDs are unique, while ad and keyword IDs are composite, requiring both the ad group ID and their individual ID for unique identification."],["The `selector.withIds()` method is used to fetch entities by ID, taking an array of numbers for campaigns and ad groups and an array of two-element arrays (ad group ID and entity ID) for ads and keywords."]]],[]]