/** * Lists 10 upcoming events in the user's calendar. * @see https://developers.google.com/calendar/api/v3/reference/events/list */functionlistUpcomingEvents(){constcalendarId='primary';// Add query parameters in optionalArgsconstoptionalArgs={timeMin:(newDate()).toISOString(),showDeleted:false,singleEvents:true,maxResults:10,orderBy:'startTime'// use other optional query parameter here as needed.};try{// call Events.list method to list the calendar events using calendarId optional query parameterconstresponse=Calendar.Events.list(calendarId,optionalArgs);constevents=response.items;if(events.length===0){console.log('Noupcomingeventsfound');return;}// Print the calendar eventsfor(consteventofevents){letwhen=event.start.dateTime;if(!when){when=event.start.date;}console.log('%s(%s)',event.summary,when);}}catch(err){// TODO (developer) - Handle exception from Calendar APIconsole.log('Failedwitherror%s',err.message);}}