google-calendar-api - Google Calendar API - 服务帐户无法查看活动详情
问题描述
更新 - 已解决(底部的解决方案)
我已经配置了一个具有域范围委派的服务帐户(允许访问其他用户资源)。我设法验证并列出另一个用户日历事件。问题是,事件不包括重要的细节,如主题、描述、被邀请者。我看到了一些东西,提到了 ACL 规则,但我不确定那是我需要的。在文档中,它提到具有域范围委派的服务帐户可以访问所有内容,因此我不确定这是我需要做的。
有过这种情况的经验的人吗?
提前致谢!
解决方案
遵循服务器到服务器应用程序的 google 文档。比在代码中,在我的情况下节点 js:
static getClient(tenantId: string, impersonateTo: string) {
// get service account credentials. JSON was produced by google while configuring the service account
const filePath = `${__dirname}/credentials/${tenantId}.json`
const content = fs.readFileSync(filePath)
const credentials = JSON.parse(content.toString())
// create authenticated client.
const auth = new google_auth_library.JWT({
email: credentials.client_email,
subject: impersonateTo,
key: credentials.private_key,
scopes: ['https://www.googleapis.com/auth/calendar'],
})
return googleapis.google.calendar({
version: 'v3',
auth,
})
}
解决方案
推荐阅读
- python - 为什么 lambda 函数不适用于列表理解,而其他一些用户定义的函数适用于列表理解?
- android - 将android studio项目复制到新电脑
- php - PHP array_map 多个参数不起作用如何解决?
- php - mySql 选择结果返回为数组中的数组
- .htaccess - Symfony4 在子文件夹中路由
- reactjs - VS代码在包含连字符的类名之间添加空格
- java - 在不实例化子类的情况下在超类和子类之间进行等效测试
- java - 可能会抛出“NullPointerException”;“上下文”在这里可以为空
- python - ValueError:无法处理连续和多类的混合
- nand2tetris - Nand2tetris.内置门芯片表现奇怪