I built the Google Apps Script application that fetches data through external API.
I get expected result when run this app, without any errors. However, when run it by Time-Driven Trigger, I get the error. Anyone know why this error occurs?
the code:
function triggerFetchTest() {
// get token
try {
var id = "my_id",
password = "my_password",
tokenUrl = ("https://api.example.jp/v1/foo/auth/get_token?id=" + id
+ "&password=" + password),
tokenResponse = UrlFetchApp.fetch(tokenUrl);
var token = JSON.parse(tokenResponse.getContentText())["token"];
Logger.log(token);
}
catch(e) {
Logger.log(e);
}
}
Additionally:
- I can get correct response if I press "RUN" button in Script Editor.
- I don't have any problem setting trigger.
- I tried to set "muteHttpExceptions": true, but the error occurred.
- The code below that shown in External APIs Doc is ok when even by triggered.
var url = 'https://gdata.youtube.com/feeds/api/videos?' + 'q=skateboarding+dog' + '&start-index=21' + '&max-results=10' + '&v=2'; var response = UrlFetchApp.fetch(url); Logger.log(response);
I want to set daily timer for this app and make the report automatically. Please give me some ideas.
*This post is my first post ever in Stackoverflow, and I'm not an English speaker in normal, so I'm sorry if you cannot read my English above...