You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Ads脚本问题:如何批量暂停多个广告系列

解决Google Ads脚本批量暂停广告系列的问题

嘿,我一眼就瞅出问题所在啦——你的脚本只暂停第一个匹配的广告系列,是因为你只处理了迭代器里的第一个元素,没循环遍历所有符合条件的广告系列!

你的原代码问题分析

你写的if (campaignIterator.hasNext())只会执行一次:取出迭代器里的第一个广告系列暂停,然后代码就结束了,剩下的test2等广告系列根本没被处理到。

修正后的代码

把if改成while循环,就能遍历所有匹配的广告系列并逐个暂停:

function main () {
  var campaignIterator = AdsApp.campaigns()
    .withCondition("Name IN ['test1', 'test2']").get();
  
  // 用while循环遍历所有匹配的广告系列
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    campaign.pause();
  }
}

关键说明

  • while (campaignIterator.hasNext())会持续检查迭代器里是否还有未处理的广告系列,直到所有元素都被遍历完
  • 每次循环里调用campaignIterator.next()取下一个广告系列,然后执行pause()操作

这样修改后,脚本就会批量暂停名称为test1和test2的所有广告系列啦!

内容的提问来源于stack exchange,提问作者Tane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 21:12:34