I'm trying to use the google Calendar API to get all events from a G-Calendar. The following code works with Node.js
const {google} = require('googleapis');
const auth = new google.auth.JWT(
CREDENTIALS.client_email,
null,
CREDENTIALS.private_key,
SCOPES
);
const getEvents = async (dateTimeStart, dateTimeEnd) => {
try {
let response = await calendar.events.list({
auth: auth,
calendarId: calendarId,
timeMin: dateTimeStart,
timeMax: dateTimeEnd,
timeZone: 'Asia/Kolkata'
});
let items = response['data']['items'];
return items;
} catch (error) {
console.log(`Error at getEvents --> ${error}`);
return 0;
}
};
But because I can't use the "require" in normal browser javascript it doesn't work.
I included
<script src="https://apis.google.com/js/api.js"></script>
and
const google = gapi;
instead of the const {google} = require('googleapis');
That in itself works but it does not recognize
const auth = new google.auth.JWT()
as a function anymore and throws an Uncaught TypeError: google.auth is undefined
I would really appreachiate if someone could help. Thank you all in advance!