我使用 JWT token 作为服务帐户的身份验证,如果我在事件中添加参与者,我会收到上述错误,我将其开发为服务,所以我可以在不使用 oauth2 授权的情况下解决这个问题吗?
const scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/gmail.send']
const calendar = google.calendar({ version: "v3" });
let rawdata = fs.readFileSync('googleCalendar\\calendarcred.json');
let CREDENTIALS = JSON.parse(rawdata);
let auth = new google.auth.JWT(
CREDENTIALS.client_email,
null,
CREDENTIALS.private_key,
scopes
);
最佳答案
为了在 Google 日历中使用服务帐户,您需要设置 Perform Google Workspace Domain-Wide Delegation of Authority到您的 gsuite 帐户。
工作区 (Gsutie) 管理员授权服务帐户后,您就可以运行模拟。请记住将身份验证设置为您希望服务帐户模拟的域中的用户。
import { JWT } from "google-auth-library";
const auth = (await google.auth.getClient({
scopes: ["https://www.googleapis.com/auth/admin.directory.user"],
})) as JWT;
auth.subject = process.env.GOOGLE_ADMIN_EMAIL;
或者,一旦服务帐户被授予访问域的权限,我认为您也可以与服务帐户共享日历,这应该可以直接访问日历,而无需模拟域中的用户。但是我认为它不会发送通知电子邮件。
关于node.js - 错误 : Service accounts cannot invite attendees without Domain-Wide Delegation of Authority,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67301923/