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