转变策略
使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。
本指南将介绍与现有效果最大化广告系列指南完全类似的构建方式,这些指南假定您将在单个原子请求中创建整个广告系列,而不是在单独的请求中逐个创建每个实体。这意味着,您需要使用临时 ID 将资源相互关联,因为在收到 API 响应之前,您不知道完整的资源名称。
为此,您必须编写一些代码,以确保不会创建任何重复的临时 ID:
let nextId = -1;
function getNextTempId() {
const ret = nextId;
nextId -= 1;
return ret;
}
对 getNextTempId
的每次连续调用都会返回一个比上一个小 1 的数字。由于所有临时 ID 都必须为负数,因此请从 -1 开始。
完成以上操作后,您现在可以创建一个数组来存储所有操作:
const operations = [];
您经常需要使用要为其制作广告系列的客户的客户 ID,因为每个资源名称都需要包含该 ID。
const customerId = AdsApp.currentAccount().getCustomerId();
每当您要创建新操作时,都将在资源名称中使用下一个临时 ID,以便稍后引用此对象,并将创建的对象插入数组:
const newOperation = {
[OPERATION_TYPE_VARIES]: {
create: {
resourceName: `customers/${customerId}/[EXACT_PATH_VARIES]/${getNextTempId()}`
// Other fields, relevant to the resource being created.
}
}
}
operations.push(newOperation);
如需了解详情并查看操作示例,请参阅 Google Ads API REST 更新文档。
构建完所有操作后,请在一个批处理中执行这些操作:
AdsApp.mutateAll(operations);
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-04。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-06-04。"],[[["This guide provides instructions on creating Google Ads Performance Max campaigns using the Google Ads API with a single atomic request, as opposed to creating each entity individually."],["To link resources within the single request, temporary IDs are utilized and assigned with a function ensuring unique negative values for each."],["The guide involves constructing an array of operations, where each operation represents the creation of a specific campaign component."],["After defining all campaign elements and their relationships through the operations array, the entire campaign structure is created by executing a single batch mutation request via `AdsApp.mutateAll(operations)`."]]],[]]