Google Calendar API:重复事件例外+主事件更新 [英] Google calendar api: recurring events exceptions + master event update

查看:77
本文介绍了Google Calendar API:重复事件例外+主事件更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下情况的应用程序:

  • 用户在我的应用程序中通过Google Calendar API v3在Google日历中创建重复活动
  • 它们更改实例之一的时间(这会很好地创建异常实例-'exception')
  • 现在他们想延长该重复发生的事件,并更改主事件的计数或结束日期

问题在于最后一步之后所有异常都消失了(日历UI似乎可以解决这个问题,但是如果通过API完成,异常就消失了).我注意到,但是Outlook通过他们的API可以很好地处理这种情况.

在这种情况下,是否有通过API在Google日历中保留例外的简单方法?

我还注意到,如果在主服务器更新后尝试进一步更新原始异常之一,则会产生错误(错误的异常"),并指出实例事件被标记为已删除,因此无法更新("get"仍会返回).在这种情况下,它创建了一个新实例事件,并使用新ID代替了原始ID.

更新

用于更新主事件的伪代码如下所示:

  let originalMastEvent = {id:" google_generation_master_event_id" ;,...重复发生:['RRULE:FREQ = WEEKLY; INTERVAL = 1; BYDAY = WE,SA; COUNT = 6'],...}//将计数从6更改为10,其余的保持不变:让newMastEvent = {id:" google_generation_master_event_id" ;,摘要:摘要",开始:{dateTime:"2020-06-24T01:00:00 + 02:00",timeZone:"UTC"},结束:{dateTime:"2020-06-24T02:00:00 + 02:00",timeZone:"UTC"},重复发生:['RRULE:FREQ = WEEKLY; INTERVAL = 1; BYDAY = WE,SA; COUNT = 10'],sendUpdates:全部",参加者:[{电子邮件:'attendee1@gmail.com'}]}const {google} = require('googleapis/build/src/index');//我在node.js上let auth = {...}//设置google api oauth obj让日历=等待google.calendar({version:'v3',auth});让res =等待calendar.events.update({calendarId:'primary',eventId:newMastEvent.id,资源:newMastEvent,sendUpdates:newMastEvent.sendUpdates}) 

解决方案

您的问题与您如何添加例外以及更新方式有关主要事件.

根据此页面此处,您需要使用<插入异常时,code> POST 请求.

因此,您将必须使用 Events:insert 请求:

  POST https://www.googleapis.com/calendar/v3/calendars/calendarId/events 

具有以下正文:

  {开始":{"dateTime":"MODIFIED_START_DATE","timeZone":"YOUR_TIMEZONE"},结束":{"dateTime":"MODIFIED_END_DATE","timeZone":"YOUR_TIMEZONE"},"recurringEventId":"ID_OF_THE_RECURRENT_EVENT","originalStartTime":{"dateTime":"ORIGINAL_DATE_TIME","timeZone":"YOUR_TIMEZONE"},"iCalUID":"ID",} 

此后,如果要更新主事件,例如扩展出现次数,则可以简单地转到以下请求:

  PUT https://www.googleapis.com/calendar/v3/calendars/calendarId/events/eventId 

具有以下正文:

  {开始":{"dateTime":"START_DATE_OF_THE_ORIGINAL_EVENT","timeZone":"YOUR_TIMEZONE"},结束":{" dateTime":"END_DATE_OF_THE_ORIGINAL_EVENT","timeZone":"YOUR_TIMEZONE"},重复发生":[" RRULE:FREQ =每周; WKST = SU; COUNT = 3; BYDAY = FR"]} 

在上述请求之后,您应该仍然可以保留异常,同时也可以扩展事件.

参考

I have an app with the following scenario:

  • user creates a recurring event in google calendar in my app (via google calendar API v3)
  • they change time of one of the instances (which creates exception instance - 'exception' in a good way)
  • now they want to extend that recurring event and they change either count or end date of the master event

The problem is that all the exceptions disappears after that last step (calendar UI seem to handle that, but if done via the API the exceptions are gone). I've noticed however that outlook manages that case just fine via their API.

Is there any simple way of preserving the exceptions in this scenario in google calendar via API?

I've also noticed that if I try to further update one of the original exceptions after the master is updated, that gives error (an 'exception' in a bad way) and points that the instance event is marked as deleted hence can't be updated ('get' still returns it). In this case it created a new instance event with a new id in place of the original one.

UPDATE

A pseudo code to update the master event would look something like this:

let originalMastEvent = {
        id:"google_generated_master_event_id",
        ...
        recurrence: [ 'RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=WE,SA;COUNT=6' ],
        ...
}

//change the count from 6 to 10, the rest stays the same:

let newMastEvent = {
    id:"google_generated_master_event_id",
    summary: 'Summary',
    start: { dateTime: '2020-06-24T01:00:00+02:00', timeZone: 'UTC' },
    end: { dateTime: '2020-06-24T02:00:00+02:00', timeZone: 'UTC' },
    recurrence: [ 'RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=WE,SA;COUNT=10' ],
    sendUpdates: 'all',
    attendees:[ { email: 'attendee1@gmail.com'} ]
}

const {google} = require('googleapis/build/src/index'); //I'm on node.js

let auth = {...} //setup google api oauth obj
let calendar = await google.calendar({version: 'v3', auth});

let res = await calendar.events.update({
    calendarId: 'primary',
    eventId: newMastEvent.id,
    resource: newMastEvent,
    sendUpdates: newMastEvent.sendUpdates
})

解决方案

Your issue is related to how are you adding the exceptions and also in the way you are updating the main event.

According to this page here you need to use a POST request when inserting an exception.

Therefore, you will have to use the Events:insert request:

POST https://www.googleapis.com/calendar/v3/calendars/calendarId/events

With the following body:

{
  "start": {
    "dateTime": "MODIFIED_START_DATE",
    "timeZone": "YOUR_TIMEZONE"
  },
  "end": {
    "dateTime": "MODIFIED_END_DATE",
    "timeZone": "YOUR_TIMEZONE"
  },
  "recurringEventId": "ID_OF_THE_RECURRENT_EVENT",
  "originalStartTime": {
    "dateTime": "ORIGINAL_DATE_TIME",
    "timeZone": "YOUR_TIMEZONE"
  },
  "iCalUID": "ID",
}

Afterwards, if you want to update the main event, for example extending the number of occurrences, you can simply to the request below:

PUT https://www.googleapis.com/calendar/v3/calendars/calendarId/events/eventId

With the following body:

{
  "start": {
    "dateTime": "START_DATE_OF_THE_ORIGINAL_EVENT",
    "timeZone": "YOUR_TIMEZONE"
  },
  "end": {
    "dateTime": "END_DATE_OF_THE_ORIGINAL_EVENT",
    "timeZone": "YOUR_TIMEZONE"
  },
  "recurrence": [
    "RRULE:FREQ=WEEKLY;WKST=SU;COUNT=3;BYDAY=FR"
  ]
}

After the above requests, you should be able to still have the exception in place while also making the extension of the event.

Reference

这篇关于Google Calendar API:重复事件例外+主事件更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆