FYI: The only step missing in above video is this one as suugested by one user in the comment section in the above article -
Source: Bard
To get calendar events via the Calendar API for today in JavaScript, you can use the following steps:
Authenticate to the Calendar API. You can do this using OAuth 2.0 or a service account. Create a new google.calendar.v3.CalendarService object. Call the events.list() method on the CalendarService object. This method will return a list of all events on the user’s calendar for the specified time period. To get events for today, you can use the following parameters: timeMin: The start of the time period. Set this to the current date at midnight. timeMax: The end of the time period. Set this to the current date at midnight plus one day.
// Import the Calendar API client library.
const { google } = require('googleapis');
// Create a new CalendarService object.
const calendarService = new google.calendar.v3.CalendarService();
// Set the timeMin and timeMax parameters.
const now = new Date();
const timeMin = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
const timeMax = new Date(timeMin.getTime() + 24 * 60 * 60 * 1000);
// Call the events.list() method to get events for today.
calendarService.events.list({
calendarId: 'primary',
timeMin: timeMin,
timeMax: timeMax,
})
.then((response) => {
// Parse the response JSON.
const events = response.data.items;
// Print the event summaries.
for (const event of events) {
console.log(event.summary);
}
})
.catch((error) => {
console.error(error);
});
// NOTE: Parse the response. The response from the events.list() method will be a JSON object containing a list of event resources. You can use a JSON parser to parse the response and extract the event information.
// Parse the response JSON.
const events = JSON.parse(response.data);
// Print the event summaries.
for (const event of events.items) {
console.log(event.summary);
}
// NOTE: All below scopes can be used together as well by using space as delimiter:
https://www.googleapis.com/auth/calendar.events https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.readonly
screenshot: 1/2
screenshot: 2/2