DEV Community

Justin Poehnelt
Justin Poehnelt

Posted on • Originally published at justin.poehnelt.com on

How to Set Google Meet Access Settings for a Calendar Event

UPDATE: You need to replace the meeting in the Calendar Event in order to edit the Meet space. See https://issuetracker.google.com/379337762.

In this post, I am going to show you how to use Google Workspace APIs to create a Calendar event and set the access settings for the Google Meet Space. This is in response to an issue opened in the Google Meet issue tracker.

I’m encountering an issue when inviting participants with non-Gmail accounts. For instance, if I invite two people—one with a Gmail account and the other without—the non-Gmail user is unable to join the meeting directly. Instead, they are prompted to request permission to join, which can be inconvenient. While I’m aware of the option to manually adjust host controls to allow all users, doing this for each meeting is impractical and tedious.

The solution is to set the space config to access type "OPEN".

{ "config": { "accessType": "OPEN" } }
Enter fullscreen mode Exit fullscreen mode

However, this requires making THREE API calls: one to create the event, one to get the Meet space from the short code, and another to update the access settings for the Google Meet space.

  1. Create a Calendar event
  2. Get the Meet space
  3. Update the access settings for the Meet space

Create a Calendar event

First, we need to create a Calendar event. We can use the Google Calendar API to do this. Here is a simple example using Node.js:

const event = (await client.events.insert({
  calendarId,
  resource: {
    summary: "summary",
    description: "description",
    // all day event
    start: {
      date,
    },
    end: {
      date,
    },
    conferenceData: {
      createRequest: {
        requestId: Math.random().toString(36).substring(7),
        conferenceSolutionKey: {
          type: "hangoutsMeet",
        },
      },
    },
  },
})).data;
Enter fullscreen mode Exit fullscreen mode

This will create a Calendar event with a Google Meet link. The conferenceData.createRequest object is required to create a Google Meet link for the event with the conferenceDataVersion parameter set to 1. Below is the partial event object:

{
  // ...
  "hangoutLink": "https://meet.google.com/rup-ghhj-obi",
  "conferenceData": {
    "createRequest": {
      "requestId": "srvg8v",
      "conferenceSolutionKey": {
        "type": "hangoutsMeet"
      },
      "status": {
        "statusCode": "success"
      }
    },
    "entryPoints": [
      {
        "entryPointType": "video",
        "uri": "https://meet.google.com/rup-ghhj-obi",
        "label": "meet.google.com/rup-ghhj-obi"
      },
      // ...
    ],
    "conferenceSolution": {
      "key": {
        "type": "hangoutsMeet"
      },
      "name": "Google Meet",
      "iconUri": "https://fonts.gstatic.com/s/i/productlogos/meet_2020q4/v6/web-512dp/logo_meet_2020q4_color_2x_web_512dp.png"
    },
    "conferenceId": "rup-ghhj-obi"
  }
}
Enter fullscreen mode Exit fullscreen mode

Get the Meet space

Using the Google Meet NodeJS client library, we can get the space using the conferenceId. First, import the library:

import { v2 as meetV2 } from "@google-apps/meet";
Enter fullscreen mode Exit fullscreen mode

Then use the SpacesServiceClient to get the space from the conferenceId:

const conferenceId = event.conferenceData.conferenceId;
const meetClient = new meetV2.SpacesServiceClient({ authClient: auth });
const space = (
  await meetClient.getSpace({
    name: `spaces/${conferenceId}`,
  })
)[0];
Enter fullscreen mode Exit fullscreen mode

This returns the following space:

{
  name: 'spaces/vIMPKJmrMMsB',
  meetingUri: 'https://meet.google.com/rup-ghhj-obi',
  meetingCode: 'rup-ghhj-obi',
  config: { accessType: 'TRUSTED', entryPointAccess: 'ALL' },
  activeConference: null
}
Enter fullscreen mode Exit fullscreen mode

Update the access settings for the Meet space

Finally, we can update the access settings for the Google Meet space using the updateSpace method:

const updatedSpace = (
  await meetClient.updateSpace({
    space: { name: space.name, config: { accessType: "OPEN" } },
    updateMask: {
      paths: ["config.access_type"], // must be in snake_case
    },
  })
)[0];
Enter fullscreen mode Exit fullscreen mode

And now the Google Meet space is set to access type “OPEN”:

{
  name: 'spaces/vIMPKJmrMMsB',
  meetingUri: 'https://meet.google.com/rup-ghhj-obi',
  meetingCode: 'rup-ghhj-obi',
  config: { accessType: 'OPEN', entryPointAccess: 'ALL' },
  activeConference: null
}
Enter fullscreen mode Exit fullscreen mode

With this solution, you can now create a Calendar event and set the access settings for the Google Meet space using the Google Workspace APIs. This will allow participants with non-Gmail accounts to join the meeting directly without having to request permission.

Complete code

The complete code for this is below:

import { authenticate } from "@google-cloud/local-auth";
import { v2 as meetV2 } from "@google-apps/meet";
import { google } from "googleapis";
const scopes = [
  "https://www.googleapis.com/auth/calendar",
  "https://www.googleapis.com/auth/meetings.space.created",
  "https://www.googleapis.com/auth/meetings.space.readonly",
];
const auth = await authenticate({
  scopes,
  keyfilePath: "./credentials.json",
});
const calendarClient = google.calendar({ version: "v3", auth });
const calendarId = "primary";
const date = new Date().toISOString().split("T")[0];
const event = (
  await calendarClient.events.insert({
    calendarId,
    // required for conferenceData
    conferenceDataVersion: 1,
    resource: {
      summary: "test event",
      description: "description",
      // all day event
      start: {
        date,
      },
      end: {
        date,
      },
      conferenceData: {
        createRequest: {
          requestId: Math.random().toString(36).substring(7),
          conferenceSolutionKey: {
            type: "hangoutsMeet",
          },
        },
      },
    },
  })
).data;
console.log(event);
// get the meeting code from the calendar event
const conferenceId = event.conferenceData.conferenceId;
const meetClient = new meetV2.SpacesServiceClient({ authClient: auth });
const space = (
  await meetClient.getSpace({
    name: `spaces/${conferenceId}`,
  })
)[0];
console.log(space);
const updatedSpace = (
  await meetClient.updateSpace({
    space: { name: space.name, config: { accessType: "OPEN" } },
    updateMask: {
      paths: ["config.access_type"], // must be in snake_case
    },
  })
)[0];
console.log(updatedSpace);

Enter fullscreen mode Exit fullscreen mode

Top comments (0)