首页 > 解决方案 > 无法读取 calendar.events.list 中未定义的属性“数据”

问题描述

我正在尝试从谷歌日历中删除事件,我列出了特定时间的所有事件,如果事件代码正确执行这些事件,则提取 id,但是当到达删除方法时,它会抛出“未处理的拒绝错误”和“无法读取属性”数据' 未定义在 calendar.events.list"

function deleteEvent(agent){

    // Use the Dialogflow's date and time parameters to create Javascript Date instances, 'dateTimeStart' and 'dateTimeEnd',
    // which are used to specify the appointment's time.
    const appointmentDuration = 1;// Define the length of the appointment to be one hour.
    const dateTimeStart = convertParametersDateD(agent.parameters.date, agent.parameters.time);
    const dateTimeEnd = addHours(dateTimeStart, appointmentDuration);
    const appointmentTimeString = getLocaleTimeString(dateTimeStart);
    const appointmentDateString = getLocaleDateString(dateTimeStart);


    //Check the availability of the time slot and delete appointment if the time slot is available on the calendar
    return deleteCalendarEvent(dateTimeStart,dateTimeEnd).then(() => {
        agent.add(`Got it. I delete your appointment scheduled on ${appointmentDateString} at ${appointmentTimeString} and i send the sendNotifications. See you soon. Good-bye.`);
}).catch(() => {
    agent.add(`Sorry, we are not booked on ${appointmentDateString} at ${appointmentTimeString}. Please choose another time and date`);
});

}//deleteEvent functin

function deleteCalendarEvent(dateTimeStart,dateTimeEnd){
    console.log("delete calender event function");

    return new Promise((resolve, reject) => {
        calendar.events.list({  // List all events in the specified time period
            auth: serviceAccountAuth,
            calendarId: calendarId,
            timeMin: dateTimeStart.toISOString(),
            timeMax: dateTimeEnd.toISOString()
        }, (err, calendarResponse) => {
            // Check if there exists any event on the calendar given the specified the time period
            if (calendarResponse.data.items.length > 0) {
            var lstOfEvent = calendarResponse.data.items;////all the events
    console.log(lstOfEvent);
    console.log('id= '+lstOfEvent[0]['id']);
    eventId=lstOfEvent[0]['id'];
    /////delete
    calendar.events.delete({

        auth: serviceAccountAuth,
        calendarId: calendarId,

        eventId:eventId
    }, (err, event) => {
        err ? reject(err) : resolve(event);
}
        );
/////delete
} else {
    reject(err);
}
});
});

}

标签: node.jsgoogle-calendar-apidialogflow-es

解决方案


推荐阅读