Reputation: 11
I wrote an Apps Script (Google Sheets) to retrieve information from Google Adsense using its service. It's enabled from the Cloud console and authorized through OAuth2
Code is:
var accountId = 'pub-1234567890'
var url = 'https://adsense.googleapis.com/v2/accounts/' + accountId + '/reports:generate';
var payload = {
startDate: {
year: oneHourAgo.getFullYear(),
month: oneHourAgo.getMonth() + 1,
day: oneHourAgo.getDate()
},
endDate: {
year: now.getFullYear(),
month: now.getMonth() + 1,
day: now.getDate()
},
metrics: ['ESTIMATED_EARNINGS', 'CLICKS', 'IMPRESSIONS'],
dimensions: ['DATE', 'PRODUCT_NAME', 'DOMAIN'],
orderBy: [{ name: 'DOMAIN', sortOrder: 'ASCENDING' },]
};
Logger.log('Request URL: ' + url);
Logger.log('Payload: ' + JSON.stringify(payload));
The log says the payload is ok:
Payload: {"startDate":{"year":2024,"month":6,"day":2},"endDate":{"year":2024,"month":6,"day":2},"metrics":["ESTIMATED_EARNINGS","CLICKS","IMPRESSIONS"],"dimensions":["DATE","PRODUCT_NAME","DOMAIN"],"orderBy":[{"name":"DOMAIN","sortOrder":"ASCENDING"}]}
But I get an Response Code: 404
I did it all following the official documentation: https://developers.google.com/adsense/management/reference/rest/v2/accounts.reports/generate#http-request
Any ideas on where is my mistake?
Upvotes: 1
Views: 74