我正在尝试从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();
}