得到"复发"来自Google Calendar API事件(React,Javascript)

时间:2017-04-21 20:37:22

标签: javascript reactjs calendar google-calendar-api

我正在尝试使用Google日历api获取事件的重复规则(RRULE),但它正在返回undefined

据说,每个事件都有一个"重复值,如here所述:

  

重复[] 列表

     

RFC5545中规定的重复事件的RRULE,EXRULE,RDATE和EXDATE行列表。请注意,此字段中不允许使用DTSTART和DTEND行;事件开始和结束时间在开始和结束字段中指定。单个事件或重复事件的实例省略此字段   可写

作为备注,

NO ISSUE:设置"重复"创建执行以下操作的事件时的值:

var event = {
   'summary': this.props.user.calendarEventTitle,
   'start': {
     'dateTime': this.props.user.calendarEventStartDateTime,
     'timeZone': this.props.user.calendarEventTimeZone
   },
   'end': {
     'dateTime': this.props.user.calendarEventEndDateTime,
     'timeZone': this.props.user.calendarEventTimeZone
   },
  "recurrence": [
     "RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z",
  ]
};


var request = window.gapi.client.calendar.events.insert({
  'calendarId': 'primary',
  'resource': event
});

request.execute(function(resp) {
  console.log('resp = ' + resp);
});

问题:不能获取"重复"获取执行以下操作的事件时的值:

listUpcomingEvents() {
   window.gapi.client.calendar.events.list({
     'calendarId': 'primary',
     'timeMin': (new Date()).toISOString(),
     'showDeleted': false,
     'singleEvents': true,
     'orderBy': 'startTime'
   }).then(function(response) {
     var events = response.result.items;

     if (events.length > 0) {
       var eventsArr = [];
       for (var i = 0; i < events.length; i++) {
         var event = events[i];
         var startDate = event.start.dateTime;
         var endDate = event.end.dateTime;
         if (!startDate) {
           startDate = event.start.date;
         }
         if (!endDate) {
           endDate = event.end.date;
         }
         var reminders = event.reminders.overrides;

         console.log('event.recurrence = ' + event.recurrence);
         {Object.keys(event).map(function(key) {
              console.log('>Key (event): ' + key + ", Value (event): " 
+ event[key]);
          })}
  

注意:我添加了上面的日志以打印出事件对象的每个键和值,但我仍然没有看到“重复”#39;键。如果此对象中没有该对象,如何获取创建此事件的重复规则?可能用repeatingEventID做什么?

         var rowArray = {
           id: event.id,
           title: event.summary,
           start: startDate,
           end: endDate,
           allDay: false,
           location: event.location,
           description: event.description,
           timeZone: event.start.timeZone,
           reminders: event.reminders.overrides,
           recurrence: event.recurrence  //ISSUE: RETURNS UNDEFINED
         };
         eventsArr.push(rowArray);
         this.setState({
           eventArray: eventsArr
         })
       }
     } else {
       console.log('No upcoming events found.');
     }
     const { calendar } = this.refs;
}

几乎看来here没有&#34;复发&#34;事件发生后的属性(仅限重复ID)。

任何提示?

1 个答案:

答案 0 :(得分:1)

对于将来有类似问题的任何人,recurringEventId可用于获取包含原始事件的重复值的不同事件。

以下是如何做到的。

获取定期事件ID,如下所示:

var recurringEventID = event.recurringEventId

然后我们再次调用Google Calendar API以获取recurringEventId(而不是event本身的ID):

var requestRecurringEvent = window.gapi.client.calendar.events.get({
        'calendarId': 'primary',
        'eventId': payload
      });
      requestRecurringEvent.execute(function(resp) {
        console.log('requestRecurringEvent = ' + resp);
        console.log('requestRecurringEvent.recurrence = ' + resp.recurrence);
        recurrence = resp.recurrence;

        console.log('recurrence (inside execute)= ' + recurrence); //NO ISSUE (YET): recurrence (inside execute) = RRULE:FREQ=WEEKLY;COUNT=10

        return recurrence;
      });

那就是它!