首页 > 解决方案 > 如何修复“未检查的 runtime.lastError:消息端口在收到响应之前关闭。” 链接到 G-Cal 事件时?

问题描述

我正在尝试生成一个链接,将用户直接带到所选的 Google 日历事件。

我生成的链接与您在通过日历界面时到达的链接相同,但是,当用户选择该链接时,它会加载一个带有 Google 日历标题和 Keep/Tasks 侧边栏的空白页面。没有加载任何实际内容,我Unchecked runtime.lastError: The message port closed before a response was received.在控制台中收到错误。这是下面的代码,但正如我所说 - 链接是相同的。

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

我搜索了错误,发现其他用户建议禁用所有扩展,但是,我没有运行任何扩展。

标签: google-chromegoogle-apps-scriptgoogle-app-maker

解决方案


我发现

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

'=='在日历链接的末尾生成几个。这些等号是中断的原因。

因此,将上面的代码编辑到下面可以解决这个问题:

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

推荐阅读