![](/img/trans.png)
[英]Accessing google Calendar API through service account in Flutter | Nodejs
[英]Google Calendar API and Service Account permission error
我正在嘗試將 Google Calendar API 集成到我的應用程序中。 到目前為止,我已經設法做到了:
現在,我在 node.js 上的代碼如下所示:
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);
我得到的錯誤是:
發送 500(“服務器錯誤”)響應:錯誤:權限不足
任何人有任何想法? 這令人沮喪。
這個改裝怎么樣?
我認為在您的腳本中,端點和/或范圍可能不正確。
在此模式中,使用您的https://dns.googleapis.com/dns/v1/projects/${keys.project_id}
端點。
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
錯誤消息的原因可能是這個。在此模式中,作為示例情況,從與服務帳戶共享的日歷中檢索事件列表。 如果日歷可以與服務帳戶一起使用,則返回事件列表。 通過這個,我認為你可以確認腳本是否有效。
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
。如果我誤解了您的問題並且這不是您想要的方向,我深表歉意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.