I'm trying to integrate the Google Calendar API in my app. So far i've managed to do this:
Now, my code on node.js looks like this:
const { JWT } = require('google-auth-library'); const client = new JWT( keys.client_email, null, keys.private_key, ['https://www.googleapis.com/auth/calendar'] ); const url = `https://dns.googleapis.com/dns/v1/projects/${keys.project_id}`; const rest = await client.request({url}); console.log(rest);
The error I get is:
Sending 500 ("Server Error") response: Error: Insufficient Permission
Anyone has any ideea? This gets frustrating.
How about this modification?
I think that in your script, the endpoint and/or scope might be not correct.
In this pattern, your endpoint of https://dns.googleapis.com/dns/v1/projects/${keys.project_id}
is used.
const { JWT } = require("google-auth-library");
const keys = require("###"); // Please set the filename of credential file of the service account.
async function main() {
const calendarId = "ip15lduoirvpitbgc4ppm777ag@group.calendar.google.com";
const client = new JWT(keys.client_email, null, keys.private_key, [
'https://www.googleapis.com/auth/cloud-platform' // <--- Modified
]);
const url = `https://dns.googleapis.com/dns/v1/projects/${keys.project_id}`;
const res = await client.request({ url });
console.log(res.data);
}
main().catch(console.error);
Insufficient Permission
might be this.In this pattern, as a sample situation, the event list is retrieved from the calendar shared with the service account. If the calendar can be used with the service account, the event list is returned. By this, I think that you can confirm whether the script works.
const { JWT } = require("google-auth-library");
const keys = require("###"); // Please set the filename of credential file of the service account.
async function main() {
const calendarId = "###"; // Please set the calendar ID.
const client = new JWT(keys.client_email, null, keys.private_key, [
"https://www.googleapis.com/auth/calendar"
]);
const url = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events`; // <--- Modified
const res = await client.request({ url });
console.log(res.data);
}
main().catch(console.error);
google-auth-library-nodejs
of the latest version.If I misunderstood your question and this was not the direction you want, I apologize.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.