首页 > 解决方案 > 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,
    })
  }

标签: google-calendar-api

解决方案


推荐阅读