3

I am attempting to generate a link that takes the user directly to the Google Calendar event selected.

The link I generate is identical to the link that you arrive at when going through the Calendar interface, however, when the user selects the link it loads a blank white page with the Google Calendar header and Keep/Tasks sidebar. None of the actual content loads and I'm given the Unchecked runtime.lastError: The message port closed before a response was received. error in console. Here's the below code, but as I said - the links are identical.

var events = [];
  var today = new Date;
  var myEvents = CalendarApp.getDefaultCalendar().getEventsForDay(today);
  var calendarId = CalendarApp.getDefaultCalendar().getId();

  myEvents.forEach(function(event){
    var eventIdSplit = event.getId().split('@');
    var newRecord = app.models.Calendar.newRecord();

    newRecord.Date = event.getStartTime();
    newRecord.Title = event.getTitle();
    newRecord.Description = event.getDescription();
    newRecord.calendarLink = 'https://calendar.google.com/calendar/r/eventedit/' + (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId));

    events.push(newRecord);
  });

I've searched the error and found that other users suggested to disable all extensions, however, I am not running any.

Elias White
  • 51
  • 1
  • 3
  • FYI, I just tried this and it works fine for me. I'm using Chrome Version 73.0.3683.103 (Official Build) (64-bit) for windows. There must be something else that we are missing. Are you opening the link in a new tab? – Morfinismo Apr 23 '19 at 12:35
  • Why are you doing this: (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId))? What happens if you make it just the event ID? – J. G. Apr 23 '19 at 18:28
  • @J.G. The event ID is not enough, you need to encode it first in order to get the correct link. – Elias White Apr 24 '19 at 01:32
  • @Morfinismo Yes, I'm using a link widget with _blank parameters on Chrome Version 74.0.3729.108 (Official Build) (64-bit) / Ubuntu 18.04. – Elias White Apr 24 '19 at 01:39

1 Answers1

2

I discovered that

newRecord.calendarLink = 'https://calendar.google.com/calendar/r/eventedit/' + (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId));

generates several '==' at the end of the calendar link. These equal signs were the cause of the break.

Therefore, editing the above code to the below solves this:

newRecord.calendarLink = 'https://calendar.google.com/calendar/r/eventedit/' + (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId)).replace(/=/g, "");
Elias White
  • 51
  • 1
  • 3