本指南假设您在单个原子请求中创建整个广告系列,而不是在单独的请求中创建每个实体。这意味着,您需要设置并使用临时 ID 来关联资源。
完成上述设置后,创建一个数组来保存所有操作:
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 mutate 文档,详细了解相关信息并查看示例操作。
构建完所有操作后,以单个批次执行这些操作:
AdsApp.mutateAll(operations);