【问题标题】:CALENDAR API : Event list is different each time i execute itCALENDAR API:每次执行时事件列表都不同
【发布时间】:2021-08-29 01:30:24
【问题描述】:

我有一个问题,每次我执行我的代码来检索日历列表,然后是我的事件。

日历列表始终相同,但每次执行代码时事件编号都不同。

有一个开始日期和结束日期,这是我的代码。

        // Make sure the client is loaded and sign-in is complete before calling this method.
  function execute() {
    return gapi.client.calendar.calendarList.list({})
        .then(function(response) {
                // Handle the results here (response.result has the parsed body).
                 let data = JSON.parse(response.body);

                for (let i = 0; i < data.items.length; i++) {
                         let calendar_id = data.items[i].id;
                         getEvents(calendar_id, function() {
                                 if(i == data.items.length -1) {
                                         addInvoices(Invoices);
                                         console.log(Invoices);
                                 }
                         });
                       
                 };
              },
              function(err) { console.error("Execute error", err); });
  }

       
  function getEvents(calendar_id, callback) {
          let start_date = new Date($('#start_date').val());
          let end_date = new Date($('#end_date').val());
          console.log(start_date);
          console.log(end_date);
    return gapi.client.calendar.events.list({
                 'calendarId': calendar_id,
                 'timeMax': end_date.toISOString(),
                 'timeMin': start_date.toISOString(),
                 'showDeleted': false,
             'singleEvents': true,
                 'orderBy': 'startTime'
         })
                .then(function(response) {
            // Handle the results here (response.result has the parsed body).
            let events = response.result.items;
                        for(let m = 0; m < events.length; m++) {
                                if(!Invoices.includes(events[m]) )
                                        Invoices.push(events[m]);
                        }
                   callback();
            return events;
           },
                          function(err) { console.error("Execute error", err);});
  }

  gapi.load("client:auth2", function() {
    gapi.auth2.init({client_id: "{{ $currentCompany->getSetting('client_id') ? $currentCompany->getSetting('client_id') : '' }}"});
  });  ``` 

Do you have any idea why i got this issue ?

【问题讨论】:

  • 在 Stack Overflow 上,我们不会在问题标题中添加“FIXED”。只需回答问题(最好更详细)并接受答案(一旦适当的时间过去)。

标签: javascript google-api google-calendar-api google-api-js-client


【解决方案1】:

已修复,我的 ajaxcontroller 中出现错误。

【讨论】:

  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-18
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 1970-01-01
  • 2014-05-23
  • 1970-01-01
相关资源
最近更新 更多