谷歌应用程序脚本缺少结束时间,但它不是的。

问题描述 投票:2回答:1

我想简单地改变一个活动的日期。我希望它是一个整天的事件,但无法弄清楚,所以我用12:00 AM - 11:59 PM。每天一次,我希望Google Apps Script在清晨运行,并将事件移动到第二天。

我得到了正确的信息,但我认为它的格式是错误的。我得到一个错误的结束时间丢失,但它不是。它只是没有以正确的格式显示。

这显然是一个测试。一旦我让一个事件正确工作,我就可以利用我的完整脚本。我已经把个人资料改成了 "xxx"...

有什么地方我做错了吗?谢谢你的帮助

Missing End Time

/**
 * Blocks current day, opens next 2 calendar days, blocks 3rd calendar day out for Book Like A Boss sync.
 */
function createEvent33() {

  var calendarId = '[email protected]'; 

  /**
 * Lists the next 10 upcoming events in the user's default calendar.
 */
  var now = new Date();
  var events = Calendar.Events.list(calendarId, {
    timeMin: now.toISOString(),
    singleEvents: true,
    orderBy: 'startTime',
    maxResults: 10
  });

 if (events.items && events.items.length > 0) {

  var todayEvent = events.items[0];

  var todayDateStart = new Date();
  todayDateStart.setDate(todayDateStart.getDate() + 1);
  todayDateStart.setHours(0);
  todayDateStart.setMinutes(0);
  todayDateStart.setSeconds(0);
  todayDateStart.setMilliseconds(0);

  var todayDateEnd = new Date();
  todayDateEnd.setDate(todayDateEnd.getDate() + 1);
  todayDateEnd.setHours(23);
  todayDateEnd.setMinutes(0);
  todayDateEnd.setSeconds(0);
  todayDateEnd.setMilliseconds(0);

  todayEvent.start = todayDateStart.toISOString();
  todayEvent.end = todayDateEnd.toISOString();   

  Logger.log(todayEvent);

      todayEvent = Calendar.Events.update(
      todayEvent,
      calendarId,
      todayEvent.id,
    );
 }}

日志。



[20-04-28 18:03:25:847 EDT] {
status=confirmed, 
creator={[email protected]}, 
id=xxxx, 
[email protected], 
sequence=6.0, 
updated=2020-04-28T13:25:13.710Z, 
end=2020-04-30T03:00:00.000Z, 
htmlLink=https://www.google.com/calendar/event?eid=xxxxxxxxxxxx, 
summary=Block Today, 
created=2020-04-27T00:26:11.000Z, 
kind=calendar#event, 
reminders={useDefault=true}, 
organizer={self=true, 
[email protected], 
displayName=Blocking Script}, 
etag="xxxxxxxxxxx", 
start=2020-04-29T04:00:00.000Z
}

[20-04-28 18:03:25:977 EDT] GoogleJsonResponseException: API call to calendar.events.update failed with error: Missing end time.
    at createEvent33(DateTest:42:36)
google-apps-script google-calendar-api updates
1个回答
1
投票

根据 文档, endstart 应该是嵌套对象而不是日期。

{
  end:{
    date: new Date()/*formatted yyyy-mm-dd*/
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.