【问题标题】:CalendarList: list not returning list of calendarsCalendarList:列表不返回日历列表
【发布时间】:2019-02-20 14:36:33
【问题描述】:

我正在尝试从 google api 获取用户日历列表:

async function main() {
    const client = new google.auth.JWT(
        privatekey.client_email,
        null,
        privatekey.private_key,
        ["https://www.googleapis.com/auth/calendar"]
    );

    const url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList';

    const res = await client.request({ url });
    console.log(res.data);
}

我得到一个空的items 数组:

info: { kind: 'calendar#calendarList',
  etag: '"p3000"',
  nextSyncToken:
   'CAASPWdvb2dsZWNhbGVuZGFyc2VydmljZUBldmVudGFwaS0yMTkwMTEuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20=',
  items: [] }
info: { kind: 'calendar#calendarList',
  etag: '"p3000"',
  nextSyncToken:
   'CAASPWdvb2dsZWNhbGVuZGFyc2VydmljZUBldmVudGFwaS0yMTkwMTEuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20=',
  items: [] }

当我使用 api explorer 时,我可以获得我需要的日历列表。有什么想法可以获取日历列表吗?

配置:

{
  "type": "service_account",
  "project_id": "xx",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----xxxn-----END PRIVATE KEY-----\n",
  "client_email": "googlecalendarservice@eventapi-219011.iam.gserviceaccount.com",
  "client_id": "111757078202416067272",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/googlecalendarservice%40eventapi-219011.iam.gserviceaccount.com"

}

【问题讨论】:

  • 然后检查您登录时使用的用户。如果 api explorer 为您列出它们,那么您的代码也应该列出它。

标签: javascript google-api google-calendar-api google-api-js-client


【解决方案1】:

需要授予服务帐户对每个日历的访问权限。

【讨论】:

  • 如何授予服务帐户访问日历的权限?
  • 好的:为此,将服务帐户的电子邮件添加到授权中(在日历中)
猜你喜欢
  • 2014-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-25
  • 1970-01-01
  • 2015-06-02
  • 1970-01-01
相关资源
最近更新 更多