0

我正在尝试从https://developers.google.com/adwords/scripts/docs/tutorials/countdown-sale实现倒计时脚本

该脚本适用于单个广告组,但在尝试多个广告组时,我不断收到以下错误:

TypeError:无法调用未定义的方法“setAdParam”。(第 9 行)

我的完整脚本是:

// Date to use to find out how many days are remaining.
var END_DATE = new Date('February 24, 2013');
// Change this to the Ad Group you set up with text ads with AdParams.
var AD_GROUP_NAMES = ['AdGroup1', AdGroup2'];

function main() {
  var timeLeft = calculateTimeLeftUntil(END_DATE);
  var adGroups = getAdGroups(AD_GROUP_NAMES);

  while (adGroups.hasNext()) {
  var adGroup = adGroups.next();
  var keywords = adGroup.keywords().get();
    // We want to update {param1} to use our calculated days and {param2} for hours.
    keywords.setAdParam(1, timeLeft['days']); // HERE COMES THE ERROR
    keywords.setAdParam(2, timeLeft['hours']); 
  }
}

var DAY_IN_MILLISECONDS = 1000*60*60*24;

function calculateTimeLeftUntil(end) {
  var current = new Date();
  var timeLeft = {};
  var daysFloat = (end - current) / (DAY_IN_MILLISECONDS);
  timeLeft['days'] = Math.floor(daysFloat);
  timeLeft['hours'] = Math.floor(24 * (daysFloat - timeLeft['days']));
  return timeLeft;
}

function getAdGroups(names) {
  var predicateValues = "['" + names.join("','") + "']";
  Logger.log(predicateValues);
  return AdWordsApp.adGroups()
      .withCondition('Name IN ' + predicateValues)
      .withLimit(names.length)
      .get();
}
4

1 回答 1

0

问题是您试图将广告参数设置为关键字迭代器,而不是单个关键字。

而不是这个

var keywords = adGroup.keywords().get();
// We want to update {param1} to use our calculated days and {param2} for hours.
keywords.setAdParam(1, timeLeft['days']); // HERE COMES THE ERROR

尝试这个:

var keywords = adGroup.keywords().get();
while (keywords.hasNext()) {
  var keyword = keywords.next();
  // and now
  keyword.setAdParam(...);
}
于 2013-04-22T21:39:45.787 回答