/** * 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);}}
[null,null,["最后更新时间 (UTC):2024-12-21。"],[[["This quickstart demonstrates how to use Google Apps Script to access the Google Calendar API and list upcoming events."],["You will need a Google Account with Google Calendar and Drive enabled to complete this quickstart."],["The script utilizes the Calendar API client library and requires authorization to access your calendar data."],["After running the script, it will display the summaries and dates/times of your upcoming events in the execution log."],["For production environments, more robust authentication methods are recommended, and further resources are provided for advanced usage and troubleshooting."]]],[]]