简体   繁体   English

谷歌日历补丁请求没有失败但也没有应用补丁

[英]Google Calendar patch request not failing but also not applying patch

I'm trying to update the recurrence rule on an event in an Apps Script application, similar to changing the end date of the recurrence in the UI and clicking "all events".我正在尝试更新 Apps 脚本应用程序中事件的重复规则,类似于在 UI 中更改重复的结束日期并单击“所有事件”。

I load the first event in the series and run Calendar.Events.patch with the new recurrence rule.我加载系列中的第一个事件并使用新的重复规则运行Calendar.Events.patch The original event has a recurrence rule of 10 occurrences, weekly on Friday.原始事件的重复规则为每周周五发生 10 次。 I get no errors, but the returned event is unchanged.我没有收到任何错误,但返回的事件没有改变。

I tried doing the same thing in the API explorer by manually copying my recurrence rule and got the same result — the returned object in the API explorer showed it ran successfully, but didn't actually update the event (the old recurrence rule was still there, instead of the new one).我尝试通过手动复制我的重复规则在API 资源管理器中执行相同的操作并得到相同的结果 - API 资源管理器中返回的 object 显示它成功运行了旧的重复规则,但实际上事件仍然没有,而不是新的)。 Why is it not failing if it's not accepting the changes?如果它不接受更改,为什么它不会失败?

My only change in the API explorer other than the event and calendar ID:除了事件和日历 ID,我在 API 资源管理器中的唯一更改:

{
  "recurrence": [
    "RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20220921T102754Z;BYDAY=FR"
  ]
}

The goal is to have a script that removes bookings from a room resource outside a predefined booking window.目标是拥有一个脚本,用于从预定义预订 window 之外的房间资源中删除预订。 The built-in AppsScript methods for RRULEs don't have a clean way to change only the RRULE without getting/setting a lot of other data about the event. RRULE 的内置 AppsScript 方法没有一种干净的方法来仅更改 RRULE 而无需获取/设置有关事件的大量其他数据。 We want to be able to set the end date as closely as possible to the end of the window while still following the other set rules for the RRULE.我们希望能够将结束日期设置为尽可能接近 window 的结束日期,同时仍遵循 RRULE 的其他设置规则。

function cleanRoom() {
  resourceId = "ID@resource.calendar.google.com" // this is a test room
  let bulkevents = JSON.parse(Calendar.Events.list("calID@resource.calendar.google.com"));
  let allevents = bulkevents.items.filter(function (e) {
    return e.recurrence != undefined // return all events with a recurrance rule
  });
  console.log('All events with recurrances:\n\n');
  // we want to look at instances of recurring events and filter down to instances more than X days in the future
  for (const x of allevents) {
    const startDT = new Date(x.start.dateTime); // ex. 2022-07-28T07:45:00-05:00
    const title = x.summary;
    // load instances — instances are what shows up on your calendar when you schedule a recurring event. instances are tied to their originator. 
    const instances = Calendar.Events.instances(resourceId,x.id);
    for (const i of instances.items) {
      // from the list of instances for an event, find any with an instance after the booking window
      // don't forget to make sure the booking window is correct in config.js
      if (luxon.DateTime.fromISO(i.start.dateTime) > luxon.DateTime.now().plus({ weeks: bookingWindow })) {
        // get the original calendar event so we can edit the end date
        let offendingEvent = Calendar.Events.get(resourceId,i.recurringEventId);
        let rrule = offendingEvent.recurrence[0];
        console.log(rrule);        
        // get last valid date in format
        let correctUntilDate = luxon.DateTime.now().plus({ weeks: bookingWindow });
        // we need to modify the original event / all events
        if (rrule.includes("COUNT")) {
                    let new_rrule = rrule.replace(regrule,'UNTIL='+correctUntilDate.set({seconds: 0}).toFormat("yyyyMMdd'T'HHmmss'Z'"));
          console.log(new_rrule);
          const calPatch = {
            'recurrence': [new_rrule]
          };
          const result = Calendar.Events.patch(calPatch,resourceId,offendingEvent.id);
          
          console.log(result);
          break;
        }
        break; // we don't need to scan every instance of every event; once it's fixed we're done, moving on to the next
      }
    }
  }
}

I tested a few minutes ago with the same request you shared and it did not work, I tested again now and it works, maybe there was an issue before.几分钟前我用你分享的相同请求进行了测试,但它没有工作,我现在再次测试,它工作,也许之前有一个问题。

If you still have the issue, try changing UNTIL=20220921T102754Z to UNTIL=20220921T102700Z , this worked for me in the API Explorer when I reproduced the same issue you were having.如果您仍然有问题,请尝试将UNTIL=20220921T102754Z更改为UNTIL=20220921T102700Z ,当我重现您遇到的相同问题时,这在API Explorer中对我有用。 All I changed is seconds from 54 to 00 in UNTIL .我所做的只是UNTIL中从5400的秒数。 Also, if you're still having issues, you can report it through the Issue Tracker .此外,如果您仍有问题,可以通过问题跟踪器报告。

If this works now in the API Explorer but not with your script please share a minimal example that reproduces the issue.如果现在在 API 资源管理器中有效,但不适用于您的脚本,请分享一个重现该问题的最小示例。

This is just a hunch, but given how PATCH semantics work, I suspect that you're ultimately adding a new rule to the recurrence array, not replacing it in its entirety.这只是一种预感,但考虑到PATCH语义的工作方式,我怀疑您最终是在向循环数组添加新规则,而不是完全替换它。

You'll probably have to use PUT semantics instead via the update endpoint .您可能不得不通过更新端点使用PUT语义。 Try experimenting with Calendar.Events.update and see if that works.尝试使用Calendar.Events.update进行试验,看看是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM