我试图将昨天的广告系列支出和点击次数提取到我的Google表格中,但我当前的设置会返回" undefined"对于我的" Clicks"列和0表示我的" TotalCost"柱。当我在帐户级别提取此数据时,我的设置很好,但是当我切换到广告系列级别时,我遇到了这些问题。关于我错误地提取数据的想法?
function main() {
var sheet = SpreadsheetApp.openByUrl(
"https://docs.google.com/spreadsheets/d/tttttt").getActiveSheet();
var emptyRow = findEmptyRow(sheet);
var yesterday = new Date(new Date().getTime() - (24 * 3600 * 1000));
var range = sheet.getRange(emptyRow + 1, 1, 1, 10);
var row = range.getValues();
row[0][0] = yesterday;
var stats = AdWordsApp.report('SELECT CampaignName, ExternalCustomerId, TotalCost, Amount, BiddingStrategyId, Impressions ' +
'FROM CAMPAIGN_PERFORMANCE_REPORT DURING YESTERDAY'
)
.rows()
.next();
row[0][1] = stats["Clicks"];
row[0][2] = stats["TotalCost"];
range.setValues(row);
}
function findEmptyRow(sheet) {
var dates = sheet.getRange(1, 1, 365, 1).getValues();
for (var emptyDate = 0; emptyDate < dates.length; emptyDate ++) {
if (dates[emptyDate][0].length == 0) {
return emptyDate;
}
}
}