I have the following basic code to read some calendar events. The calendar is publicly shared from a normal private google user.
To use google api, I set up a service account with owner role, just to make things simple at first. By using https://deno.land/x/google_deno_integration I try to make sure I'm using OAuth2, and according to this answer access is possible
import { GoogleAPI } from "https://deno.land/x/google_deno_integration/mod.ts";
const serviceAccountConfig = await Deno.readTextFile(Deno.env.get('GOOGLE_APPLICATION_CREDENTIALS'));
const credentials = JSON.parse(serviceAccountConfig);
const cal_id = 'my-cal-id';
const api = new GoogleAPI({
email: "[email protected]",
scope: ["https://www.googleapis.com/auth/calendar.events"],
key: credentials.private_key,
});
const calget = await api.get(`https://www.googleapis.com/calendar/v3/calendars/${cal_id}`);
console.log(calget);
Unfortunately, this is the answer I get:
$ deno run --allow-env --allow-read --allow-net index.2.ts
{
error: {
code: 403,
message: "Request had insufficient authentication scopes.",
errors: [
{
message: "Insufficient Permission",
domain: "global",
reason: "insufficientPermissions"
}
],
status: "PERMISSION_DENIED",
details: [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
reason: "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
domain: "googleapis.com",
metadata: {
service: "calendar-json.googleapis.com",
method: "calendar.v3.Calendars.Get"
}
}
]
}
}
I don't know if I'm settings my service account badly (first hour user of google cloud here), if what I'm doing is possible, or if it's something wrong I'm not considering.
Yes it you can use a service account to read a public calendars. The key to this is it must be public. Which means you are only going to have read only access to it.
In the below example. I am reading from the Danish holiday calendar.
I really don't know why you would want to when you can use just use an API key and get the same result
Deno
If you check the doc you linked google_deno_integration it clearly states Google Integration and Authentication for Deno. This is not the same as authorization which is what you need.
There for I dont think that function will work.
If you are willing to use an api key then you just need to do a http get. Which appears to be possible using fetch
The url format is
So using the example above for the Danish holiday calendar you have
or