我正在编写一个Google App脚本,可以从gSuite中提取Chromebook设备信息。我需要将其导出为CSV以将其导入数据库。然而,我遇到了一个问题。 API“AdminDirectory.Chromeosdevices.list”限制为100个maxResults。我有超过30,000个结果。
这是我的测试代码。
function updateDeviceList() {
var page, pageToken, row, dateTime;
dateTime = getDateTime();
deleteAllRows();
do {
page = AdminDirectory.Chromeosdevices.list("my_customer",
{
domain: 'redclayschools.com',
maxResults: 115,
orderBy: 'annotatedUser',
pageToken: pageToken,
projection: 'full',
query: 'id:*'
});
for (i in page.chromeosdevices) {
row = getLastRow();
writeToCell(row, 1, page.chromeosdevices[i].orgUnitPath);
writeToCell(row, 2, page.chromeosdevices[i].annotatedUser);
writeToCell(row, 3, page.chromeosdevices[i].annotatedLocation);
writeToCell(row, 4, page.chromeosdevices[i].annotatedAssetId);
writeToCell(row, 5, page.chromeosdevices[i].serialNumber);
writeToCell(row, 6, page.chromeosdevices[i].lastEnrollmentTime);
writeToCell(row, 7, page.chromeosdevices[i].deviceId);
writeToCell(row, 8, page.chromeosdevices[i].bootMode);
writeToCell(row, 9, page.chromeosdevices[i].recentUsers);
writeToCell(row, 10, page.chromeosdevices[i].macAddress);
writeToCell(row, 11, page.chromeosdevices[i].lastSync);
writeToCell(row, 12, page.chromeosdevices[i].osVersion);
writeToCell(row, 13, page.chromeosdevices[i].platformVersion);
writeToCell(row, 14, page.chromeosdevices[i].activeTimeRanges);
writeToCell(row, 15, page.chromeosdevices[i].model);
writeToCell(row, 16, page.chromeosdevices[i].etag);
writeToCell(row, 17, page.chromeosdevices[i].firmwareVersion);
writeToCell(row, 18, page.chromeosdevices[i].status);
writeToCell(row, 19, page.chromeosdevices[i].ethernetMacAddress);
writeToCell(row, 20, page.chromeosdevices[i].notes);
writeToCell(row, 21, dateTime);
}
} while (pageToken){
}
}
我的助手功能(这应该无关紧要):
function writeToCell(row, column, text) {
sheet.getRange(row, column).setValue(text);
}
是否有更好的功能使用(我似乎找不到任何东西),或者绕过100 maxResult限制?我知道直接写入行的方法效率不高,这只是测试代码。
谢谢!