I am not able to figure out a proper flow in accessing google calendar rest API’s without using inbuilt methods of googleapis
liberary to modify the event/access them. All the solutions found to acccess google calendar uses in-built methods of googleapis
and also https://developers.google.com/calendar/caldav/v2/guide#connecting_to_googles_caldav_server says we need to perform oauth and then connect.
Note: can use module for oAuth and not for modifying/accessing calendar
something like below
const express = require("express");
const { google } = require("googleapis");
const dotenv = require("dotenv");
const axios = require("axios");
app.get("/request", async (req, res) => {
const oauth2Client = new google.auth.OAuth2(
process.env.CLIENT_ID,
process.env.SECRET_ID,
process.env.REDIRECT_URL
);
const token = oauth2Client.credentials.access_token;
try {
const response = await axios({
method: "PROPFIND", // Use PROPFIND to fetch calendar data from CalDAV
url: `https://apidata.googleusercontent.com/caldav/v2/${calid}/events/`, // Google CalDAV endpoint
headers: {
Authorization: `Bearer ${token}`,
Depth: "1",
"Content-Type": "application/xml"
},
data: `
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag />
<C:calendar-data />
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT" />
</C:comp-filter>
</C:filter>
</C:calendar-query>
`
});
console.log("CalDAV Response:", response.data);
} catch (error) {
console.error("Error fetching calendar data:", error);
}
});
0
was able to figure out the issue, by enabling CalDAV API as only enabled Google Calendar API which was to use along with library