I have the following code that I made by modifying the listUpcomingEvents()
method in this quickstart guide for using the google calendar api.
function getEvents(starttime,endtime) {
var request = gapi.client.calendar.events.list({
'calendarId': 'primary',
'timeMin': (starttime).toISOString(),
'timeMax': (endtime).toISOString(),
'showDeleted': false,
'singleEvents': true,
'orderBy': 'startTime'
});
request.execute(function(resp) {
console.log(resp.items);
});
}
This prints out an array of the events in the user's calendar between the provided start and end time.
The problem is I want getEvents
to return this array rather than printing it. I cannot seem to figure out how to do this though.
I have attempted replacing the last three lines with:
return request.execute(function(resp) {
return resp.items;
});
and:
var temp;
request.execute(function(resp) {
temp = resp.items;
});
return temp
but neither of these work. Any tips would be appreciated.