function GET_ADWORDS(_customer, _developer) {
// Google Ads API
const url = 'https://googleads.googleapis.com/v13/customers/{customer_id}/googleAds:searchStream'.replace('{customer_id}', _customer);
const prms = {
muteHttpExceptions: true,
method: 'POST',
headers: {
accept: 'application/json',
// OAuth のアクセストークンを指定
authorization: 'Bearer {access_token}'.replace('{access_token}', ScriptApp.getOAuthToken()),
'content-type': 'application/json',
// 開発者キーを指定
'developer-token': _developer,
},
payload: JSON.stringify({
query: [
// GAQL を記述
'SELECT',
[
'segments.date',
'metrics.impressions',
'metrics.clicks',
'metrics.cost_micros',
].join(','),
'FROM landing_page_view',
'WHERE segments.date DURING LAST_7_DAYS',
'ORDER BY segments.date',
].join(' ')
})
};
//console.log(UrlFetchApp.getRequest(url, prms));
const res = UrlFetchApp.fetch(url, prms);
const sts = res.getResponseCode();
console.log(['STATUS', sts]);
console.log(res.getAllHeaders());
const cnt = res.getContentText();
if (sts !== 200) {
console.error(cnt);
} else {
console.log(cnt);
}
var obj;
try {
obj = JSON.parse(cnt);
} catch (_error) {
console.error(_error);
}
return obj[0].results.map(function (_row) {
// 結果が文字列で返ってくるので数値変換
return [_row.segments.date, _row.metrics.clicks * 1, _row.metrics.impressions * 1, _row.metrics.costMicros / 1000000];
});
}