Apps 脚本高级日历 API - 插入带有标题的新事件 - 错误 "Invalid source url:"

Apps Script Advanced Calendar API - insert new event with Title - Error "Invalid source url:"

我正在使用 "built-in" Advanced Apps Script Calendar API(不是 REST API)并尝试创建一个新的日历事件,但出现错误:

Invalid source url:

我直接从日历中获取日历 ID,所以我认为不是那个。

function createCalEvent() {
  var event, calendarId, endTime, newEvent, options, 
      response, resource, startTime, title, url;

  var cal = CalendarApp.getCalendarsByName("Main Calendar");

  calendarId = cal[0].getId();//   
  Logger.log('calendarId: ' + calendarId)

  title = "Test Event Title";

  startTime = "2018-7-18T09:00:00";
  endTime = "2018-7-18T12:00:00";

  resource = {
    "start": {
      "dateTime": startTime,
      "timeZone": "GMT-08:00"
    },
    "description": "Test the description",
    "source": {
      "title": title
    }
  }

  if (endTime) {

    var o = {
      "dateTime": endTime,
      "timeZone": "GMT-08:00"
    }

    resource.end = o;
  } else {
    resource.endTimeUnspecified = true;
  }

  response = Calendar.Events.insert(resource, calendarId);
  Logger.log('response: \n' + response)

}

我正在尝试设置活动的标题。

当它为Calendar.Events.insert()设置事件标题时,请在请求body中包含属性 summarysource 不是为了给活动标题。所以请修改如下。

修改脚本:

resource = {
  "start": {
    "dateTime": startTime,
    "timeZone": "GMT-08:00"
  },
  "description": "Test the description",
  "summary": "event title", // Added
  // "source": {"title": title} // Removed
}

注:

  • 如果您在请求 body 中使用 "source",请像 "source": {"title": title, "url": "http://localhost"} 一样同时包含 source.titlesource.url。当不包含source.url时,出现Invalid source url: .的错误。

参考: