Google Calendar API client for JavaScript. This is created with great influence from those repositories.
- https://github.com/Kubessandra/react-google-calendar-api
- https://github.com/googleapis/google-api-nodejs-client
// with npm
npm install google-calendar-api-client
// with yarn
yarn add google-calendar-api-client
-
Prepare client id and api key. https://console.cloud.google.com/apis/credentials
-
Init api client with those params.
import { CalendarApiClient } from "google-calendar-api-client";
const apiClient = new CalendarApiClient({
clientId: process.env.CLIENT_ID,
apiKey: process.env.API_KEY,
scope: "https://www.googleapis.com/auth/calendar.events",
discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"],
});
- Use this.
const listEvents = async () => {
const day = dayjs();
await apiClient.listEvents({
timeMin: day.toISOString(),
timeMax: day.add(1, "month").toISOString(),
maxResults: 20,
singleEvents: true,
orderBy: "startTime",
});
};