I need to display all events of user from his calendars. I get a list of all calendars and then loop through each one get events and try to store them in an array.
app.get('/getEventsList/', function (req, res) {
newArray = [];
function Done(){
console.log(newArray);
}
function getEventsforOneCalendar(token,calid){
gcal(token).events.list(calid, function(err, eventsList) {
newArray.push(eventsList);
});
}
function getEventsList(token) {
gcal(token).calendarList.list(function (err, calendarList) {
if (err) {
//handle error
} else {
calendars = calendarList.items;
forEach(calendars, function (item, index) {
getEventsforOneCalendar(token,item.id);
}, Done);
}
});
}
getEventsList('xxxxxxxxxxxtoken');
});
Problem is: that line newArray.push(eventsList);
Any value even static passed in this line doesn't go like newArray.push('test'); and no error is thrown. if I log it I see it in the console, but it's never added to the array.
What's possibly wrong?