gpt4 book ai didi

google-calendar-api - 在nodejs应用程序中调用时日历列表不返回结果

转载 作者:行者123 更新时间:2023-12-03 19:39:06 24 4
gpt4 key购买 nike

let scopes = ["https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/calendar.readonly"];
if (checker(googleKey)&&checker(jwtClient)) {
jwtClient = new google.auth.JWT(
googleKey.client_email,
null,
googleKey.private_key, scopes,
null
);
jwtClient.authorize(function jwtAuth(err, tokens) {
if (err) {
res.json({ error: "Failed to execute auth command " });
return;
}

let calendar = google.calendar('v3');
calendar.calendarList.list({
auth: jwtClient
}, function(err, resp) {
if (err || !resp.items) {
res.json({ error: "Failed to execute calendar list request " });
return;
}
let calendars = resp.items.map(cal => { if (cal.summary) return { id: cal.id, txt: cal.summary } });
res.json(calendars);
});
});
}

因此,上面的代码对启用了日历 api 的帐户中的日历列表进行了 jwt 授权调用。当我进入控制台时,我什至可以看到成功的请求,但是我从 nodejs 得到的结果是一个空数组,就像我在 api 资源管理器中测试它一样,我得到了正确的结果..这是怎么回事?

最佳答案

这是一个一年前的问题,但也许其他人会从答案中受益。您应该在代码中使用“数据”而不是“项目”。这是工作示例:

async function listCalendars() {
// console.log( calendar.calendarList);
calendar.calendarList.list({
auth: oauth2Client,
maxResults: 100
},
function (err, result) {
console.log(result.data.items);
}
);
}

listCalendars().catch(console.error);

关于google-calendar-api - 在nodejs应用程序中调用时日历列表不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42815321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com