0
votes

I am trying to get the recurrence rules (RRULE) for an event using the google calendar api, but it is returning undefined.

Supposedly, each event has a "recurrence value as stated here:

recurrence[] list

List of RRULE, EXRULE, RDATE and EXDATE lines for a recurring event, as specified in RFC5545. Note that DTSTART and DTEND lines are not allowed in this field; event start and end times are specified in the start and end fields. This field is omitted for single events or instances of recurring events.
writable

As a note,

NO ISSUE: SET the "recurrence" value when creating an event doing the following:

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);
});

ISSUE: Cannot GET the "recurrence" value when fetching an event doing the following:

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]);
          })}

NOTE: I added the log above to print out every key and value of the event object, but I still don't see a 'recurrence' key. If there isn't one in this object, how do I get the recurrence rules that are creating this event? Possibly do something with the 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;
}

It almost appears here that there is no "recurrence" property once the event is made (only a recurrence id).

Any tips?

1

1 Answers

1
votes

For anyone that has a similar question in the future, the recurringEventId can be used to fetch a different event which contains the recurrence value for the original event.

Here's how you can do it.

Get the recurring event ID like so:

var recurringEventID = event.recurringEventId

Then use that id to make another call to the Google Calendar API for the recurringEventId (rather than the id of event itself):

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;
      });

And that's it!