【发布时间】: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