无法读取calendar.events.list中未定义的属性“数据”

时间:2019-05-08 20:38:44

标签: node.js google-calendar-api dialogflow

我正在尝试从Google日历中删除事件,我已经列出了特定时间的所有事件并提取了if事件的ID 代码正确执行了这些操作,但是当到达删除方法时,它会引发“意外的抛出错误”和“无法读取未定义的属性'data'     在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);
}
});
});

}

0 个答案:

没有答案