我试图在google日历中创建一个新的事件,并将Hangout meets链接发送给用户。我使用的是GSuite的委托凭证,在Node js中不容易找到这方面的文档。我找到了这个 岗位 如何列举事件,它工作得很好。但是当我用它来创建事件时,我得到了这个错误。
UnhandledPromiseRejectionWarning: 错误。未找到 在Gaxios.C:optt/node_modules/gaxios/build/src/gaxios.js:73:27)在Generator.next()处履行(C:optt/node_modules/gaxios)。(C:\optt\node_modules\gaxios\build\src\gaxios.js:73:27)在Generator.next()在履行(C:\optt\node_modules\gaxios\build\src\gaxios.js:16:58)在processTicksAndRejections(internalprocesstask_queues.js:97:5)(node:23328)UnhandledPromiseRejectionWarning。Unhandled promise rejection。这个错误源于没有 catch 块的异步函数内部的抛出,或者是拒绝一个没有用 .catch() 处理的承诺。要在未处理的承诺拒绝时终止节点进程,请使用 CLI 标志。--unhandled-rejections=strict
(见 https:/nodejs.orgapicli.html#cli_unhandled_rejections_mode。). (rejection id: 1)(node:23328) [DEP0018] DeprecationWarning: 未处理的承诺拒绝已被废弃。今后,未处理的承诺拒绝将以一个非零的退出代码终止Node.js进程。
这是我的代码。
const google = require("googleapis").google;
const calendar = google.calendar("v3");
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2020-06-12T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2020-06-12T12:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'conferenceData': {
'createRequest': {
'conferenceSolutionKey': {
'type': 'hangoutsMeet'
},
'requestId': 'iyfuted65e3ers'
}
},
'attendees': [
{'email': '[email protected]'},
{'email': '[email protected]'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
};
(async function () {
const scopes = ['https://www.googleapis.com/auth/calendar'];
const keyFile = './credentials.json';
const client = await google.auth.getClient({
keyFile,
scopes,
});
// Delegated Credential
client.subject = '[email protected]';
const res = await calendar.calendarList.insert({
auth: client,
calendarId: 'primary',
conferenceDataVersion: 1,
resource: event,
});
//listEvents();
console.log(JSON.stringify(res.data));
})();
我插入的数据是错误的。这里是写的代码,如果有人需要的话。
const google = require("googleapis").google;
const calendar = google.calendar("v3");
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2020-06-12T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2020-06-12T12:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'conferenceData': {
'createRequest': {
'conferenceSolutionKey': {
'type': 'hangoutsMeet'
},
'requestId': 'iyfuted65e3ers'
}
},
'attendees': [
{'email': '[email protected]'},
{'email': '[email protected]'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
};
(async function () {
const scopes = ['https://www.googleapis.com/auth/calendar'];
const keyFile = './credentials.json';
const client = await google.auth.getClient({
keyFile,
scopes,
});
// Delegated Credential
client.subject = '[email protected]';
const res = await calendar.calendar.events.insert({
auth: client,
calendarId: 'primary',
conferenceDataVersion: 1,
resource: event,
});
//CreateEvents();
console.log(JSON.stringify(res.data.hangoutLink));
})();