I'm using deno and https://googleapis.deno.dev/ to try to get some events from a publicly shared calendar.
Basically, this is the code:
import { Calendar, auth } from "https://googleapis.deno.dev/v1/calendar:v3.ts";
const serviceAccountConfig = await Deno.readTextFile(Deno.env.get('GOOGLE_APPLICATION_CREDENTIALS'));
const credentials = auth.fromJSON(JSON.parse(serviceAccountConfig));
const calendar = new Calendar(credentials);
const cal = await calendar.eventsGet('<my-public-calendar-id-here>');
console.log(cal);
but this is what I get:
error: Uncaught (in promise) GoogleApiError: 401: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
throw new GoogleApiError(
^
at request (https://googleapis.deno.dev/_/base@v1/mod.ts:27:13)
at eventLoopTick (ext:core/01_core.js:183:11)
at async Calendar.eventsGet (https://googleapis.deno.dev/v1/calendar:v3.ts:476:18)
I've tried to check if some calendar privilege is needed for the google service account I use, but I haven't found any. Plus, this code is supposed to run on a backend, so I guess I should use a service account, not a user token (and keep in mind what I want to get has public access). Any piece of suggestion?
My code.