首页 > 解决方案 > Google API 日历承诺

问题描述

我尝试使用 Google API 日历插入一堆事件并获取插入事件的 ID,但我无法获得响应。我不知道我做错了什么。

这就是我在做什么:

GetEvents //fetchs the user events 
        .then(insertEvents)
        .catch(function (reason) {
            console.log(reason);
        });

function insertEvents(events) {

    var eventsToInsert = [];
    if (events.length) {
        for (evnt of events) {  //Here im creating an array of //"promises" that return the insert method of google API
            eventsToInsert.push(insertEvent(evnt.titulo, evnt.lugar, evnt.fechainicio, evnt.fechafin, evnt.tipologia,
                evnt.id))
        }
        console.log('Events ti insert');
        console.log(eventsToInsert);
        //And here im trying the return the resolved data by the all //promises, but it returns an empty array always
        Promise.all(eventsToInsert.map(function (eventToInsert) {
            return eventToInsert.execute(function (event) {
                console.log('event', event);
                 return event.id;
            });
        })).then(function (res) {
            console.log(res);
        });

    } 

}

提前致谢

标签: javascriptgoogle-calendar-api

解决方案


推荐阅读