How to use the calendar function from googleapis

Find comprehensive JavaScript googleapis.calendar code examples handpicked from public code repositorys.

googleapis.calendar is a module that allows users to interact with Google Calendar API.

2
3
4
5
6
7
8
9
10
11
12


class GoogleCal {
  constructor(configuration) {
    this.configuration = configuration;
    this.scopes = ['https://www.googleapis.com/auth/calendar.readonly'];
    this.googleCal = google.calendar({
      version: 'v3',
      auth: this.configuration.GOOGLE_CALENDAR_API_KEY,
    });
  }
fork icon25
star icon34
watch icon9

+ 10 other calls in file

How does googleapis.calendar work?

googleapis.calendar is a module for interacting with the Google Calendar API, providing functions for creating, updating, and deleting events, as well as managing calendars and notifications, among other features. It uses the OAuth 2.0 protocol for authentication and authorization, and sends HTTP requests to the Google Calendar API endpoint.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { google } = require("googleapis");
const auth = new google.auth.GoogleAuth({
  keyFile: "path/to/keyfile.json",
  scopes: ["https://www.googleapis.com/auth/calendar"],
});

async function createEvent() {
  const calendar = google.calendar({ version: "v3", auth });
  const event = {
    summary: "Google I/O 2023",
    location: "Moscone Center, San Francisco, CA",
    description: "A chance to hear more about Google's developer products.",
    start: {
      dateTime: "2023-05-28T09:00:00-07:00",
      timeZone: "America/Los_Angeles",
    },
    end: {
      dateTime: "2023-05-28T17:00:00-07:00",
      timeZone: "America/Los_Angeles",
    },
    reminders: {
      useDefault: true,
    },
  };
  const { data: createdEvent } = await calendar.events.insert({
    calendarId: "primary",
    resource: event,
  });
  console.log(`Event created: ${createdEvent.htmlLink}`);
}

createEvent();

In this example, we are creating an event in the primary calendar associated with the authenticated user's Google account. The googleapis.calendar module provides a client for the Google Calendar API, which we use to create the event by making a POST request to the events.insert endpoint with the relevant data. Once the event is successfully created, we log its HTML link to the console.