2

I have an application used for the room booking which connects to a G Suite calendar and allows you to list/book/cancel meetings.

To do so, a request is made initially to collect the list of email resources associated to a service account, like this: https://developers.google.com/calendar/v3/reference/calendarList/list

The request works but only returns the old resources, not the new ones. Note: If I try directly in the Google API using the admin authentication then I get all the resources.

Here's my sample code:

const { GoogleToken } = require('gtoken');

const { XMLHttpRequest } = require('xmlhttprequest');

const gtoken = new GoogleToken({
  keyFile: 'signmeeting-gsuite-0ffd58e3a355.json',
  scope: [
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/calendar.readonly'
  ] // or space-delimited string of scopes
});

gtoken.getToken(async (err, tokens) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(tokens);
  try {
    await sendXhrRequest(tokens);
  } catch (error) {
    console.log(error);
  }
});

async function sendXhrRequest(tokens) {
  try {
    const xhr = new XMLHttpRequest();
    xhr.addEventListener("load", onLoad);
    xhr.addEventListener("error", onError);
    xhr.open("GET", "https://www.googleapis.com/calendar/v3/users/me/calendarList");
    xhr.setRequestHeader("Authorization", "Bearer " + tokens.access_token);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send();
  } catch (error) {
    console.log(error);
  }
}

function onLoad() {
  console.log(this.status);
  if (this.responseText) {
    console.log(JSON.parse(this.responseText));
  }
}

function onError() {
  console.log(this.status);
}

Could you please tell me what has changed in the Google API so that the new resources are not returned? And how to fix it?

Note: I have noticed that the old resources email address start with the org unit as a prefix but not the new ones.

Thanks in advance

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

1 Answers1

1

CalendarList.list returns all of the calendars which have been added to the current authenticated users calendarList.

The calendarList appears at the bottom left hand side of the google calendar web application. This list is not always kept up to date it depends on how the current authenticated user was granted access to this new calendar. If it was done though the web application it should be added unless you are using a service account. (Note: it used to be added automatically with service accounts but this was removed a while ago)

If one user does not have them in their calendarList then i suggest you just do a calendarList.Insert and add it.

service account

Here is some official info from google as to why service accounts no longer automatically have shared calendars in calendarlist.

Service Accounts don't accept automatically shared calendars anymore

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Thanks for the quick response! Yes I'm using a service account and that must be why it no longer works. Is there any solution to still do it via the google calendar web application with a service account? – admin gsuite Nov 06 '20 at 10:17
  • set up some code that will insert it into the calendarlist for the service account. and run it every time you share it thats really the only option. update to link on the issue forum as to why they wont fix it. – Linda Lawton - DaImTo Nov 06 '20 at 10:39