ID
大多数 Google Ads 实体都公开了用于返回其标识符的 getId()
方法。虽然在大多数情况下,ID 并非绝对必要,但在以下情况下,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-03-04。
[null,null,["最后更新时间 (UTC):2025-03-04。"],[[["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."]]],[]]