我正在使用一个函数,使用Mailchimp API中的数据填充Google表格文档。 而不是只为不同的ID复制粘贴整个函数,而是在尝试使用不同的参数运行同一函数。
但是我遇到了一些问题,需要帮助。
下面的代码总共填充200条记录。但是,我要寻找的结果是每张纸有200条记录(总计600条)。该怎么办?
代码
function runme() {
mailchimpListGrowthT ('4a565a', 'SE');
mailchimpListGrowthT ('781235', 'ES');
mailchimpListGrowthT ('876556', 'AU');
}
正在运行的功能(Google脚本代码)
var COUNT = '200';
function mailchimpListGrowthT(LIST_ID, TAB_NAME) {
// URL and params for the Mailchimp API
var root = 'https://us12.api.mailchimp.com/3.0/';
var endpoint = 'lists/' + LIST_ID + '/growth-history?count=' + COUNT;
var params = {
'method': 'GET',
'muteHttpExceptions': true,
'headers': {
'Authorization': 'apikey ' + API_KEY
}
};
try {
// call the Mailchimp API
var response = UrlFetchApp.fetch(root+endpoint, params);
var data = response.getContentText();
var json = JSON.parse(data);
// get just list history data
var listGrowth = json['history'];
// blank array to hold the list growth data for Sheet
var monthlyGrowth = [];
// Add the list growth data to the array
listGrowth.forEach(function(el) {
monthlyGrowth.push([el.month, el.existing, el.optins, el.imports]);
});
// Log the monthlyGrowth array
Logger.log(monthlyGrowth);
// select the list growth output sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(TAB_NAME);
// calculate the number of rows and columns needed
var numRows = monthlyGrowth.length;
var numCols = monthlyGrowth[0].length;
// output the numbers to the sheet
sheet.getRange(4,1,numRows,numCols).setValues(monthlyGrowth.reverse());
// adds formulas for absolute and relative growth
for (var i = 0; i < numRows; i++) {
sheet.getRange(4+i,5).setFormulaR1C1('=iferror(R[0]C[-3] - R[-1]C[-3],0)'); // absolute monthly change in list
sheet.getRange(4+i,6).setFormulaR1C1('=iferror((R[0]C[-4] - R[-1]C[-4])/R[-1]C[-4],0)').setNumberFormat("0.00%"); // rate of change in list
}
}
catch (error) {
// deal with any errors
Logger.log(error);
};
}