function main() {
const spreadsheet = SpreadsheetApp.openByUrl(sheetUrl);
const targetSheet = spreadsheet.getSheetByName("シート1");
const report = AdWordsApp.report(
'SELECT ResponsiveSearchAdDescriptions, ResponsiveSearchAdHeadlines ' +
'FROM AD_PERFORMANCE_REPORT ' +
'WHERE AdType = RESPONSIVE_SEARCH_AD '
);
// reportの中身を確認
Logger.log("report: ", report);
const rows = report.rows();
Logger.log("rows: ", rows);
const descriptionData = [];
const headlineData = [];
// rowsの中身を確認
Logger.log("rows: ", rows);
while (rows.hasNext()) {
const row = rows.next();
Logger.log("row: ", row);
Logger.log("ResponsiveSearchAdDescriptions: ", row['ResponsiveSearchAdDescriptions']);
// 2023/5/23 16:35:25 ResponsiveSearchAdHeadlines::::
const descriptions = JSON.parse(row['ResponsiveSearchAdDescriptions']);
if (descriptions.length === 0) {
Logger.log("ResponsiveSearchAdDescriptions is empty");
} else {
descriptions.forEach(function(v){
Logger.log("v: ", v);
const assetId = v.assetId || "";
const assetText = v.assetText || "";
Logger.log("assetId: ", assetId);
Logger.log("assetText: ", assetText);
targetSheet.appendRow(['description', assetId, assetText]);
});
}
const headlines = JSON.parse(row['ResponsiveSearchAdHeadlines']);
if (headlines.length === 0) {
Logger.log("ResponsiveSearchAdHeadlines is empty");
}
headlines.forEach(function(v){
Logger.log("v: ", v);
const assetId = v.assetId || "";
const assetText = v.assetText || "";
Logger.log("assetId: ", assetId);
Logger.log("assetText: ", assetText);
targetSheet.appendRow(['headline', assetId, assetText]);
}
);
}
}
Log:::
2023/5/23 17:00:04 report:
2023/5/23 17:00:04 rows:
2023/5/23 17:00:04 rows:
2023/5/23 17:00:06 row: