CalendarList:列表不返回日历列表

时间:2019-02-20 14:36:33

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

我正在尝试从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资源管理器时,可以获取所需的日历列表。有什么想法可以获取日历列表吗?

config:

{
  "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"

}

1 个答案:

答案 0 :(得分:0)

需要授予服务帐户访问每个日历的时间。