我正在编写日历集成,并使用Google calendar api和Outlook Graph api来同步日历事件。当事件发生变化时,我会收到webhooks,所以重要的是事件在不同的日历提供商之间是相同的。
但是,当我更新Google活动的活动参与者时,不会向Outlook参与者发送活动更新。结果是Outlook与会者没有准确的与会者列表。
如果我更改标题/描述/时间,Google将发送事件更新,Google和Outlook事件将同步( Outlook事件将使用正确的参与者列表进行更新)。
我曾尝试更新用户看不到的字段(例如:序列、扩展属性),希望更改会触发来自Google的事件更新,但似乎不起作用。
有没有人找到了在添加或删除参与者时触发Google事件更新的方法?
更新:对于Outlook用户,我为每个用户的日历创建了一个订阅(使用图形SDK):
var graphClient = await MicrosoftAuthenticationProvider.GetGraphClient(CALENDAR_CLIENT_ID, CALENDAR_CLIENT_SECRET, CALENDAR_REDIRECT_URI, CALENDAR_ACCESS_SCOPES, RefreshToken).ConfigureAwait(false);
var tmpSubscription = new Subscription
{
ChangeType = WEBHOOK_SUBSCRIPTION_CHANGETYPE,
NotificationUrl = WEBHOOK_NOTIFICATION_ENDPOINT,
Resource = WEBHOOK_EVENT_RESOURCE_NAME,
ExpirationDateTime = maxSubscriptionLength,
ClientState = clientState
};
var subscription = await graphClient.Subscriptions
.Request()
.AddAsync(tmpSubscription)
.ConfigureAwait(false);更新Outlook事件时,我的webhook通知终结点将收到来自Outlook的通知。当我在Google中编辑事件的摘要、描述、开始或结束时,这会成功地发生。当我添加或删除与会者时,不会发生此问题。
要复制:在Google中创建具有使用Outlook的参与者的活动。您将在Outlook中看到该事件。将另一个参与者添加到Google活动中。Google不会向Outlook发送更新电子邮件(就像标题/时间/描述更改时的方式一样)。谷歌和Outlook的活动参与者现在不同了。
发布于 2020-06-08 22:59:12
我找到了一个变通方法:
如果我知道与会者发生了变化,我会更改事件的描述,并向Google发送一个静默补丁请求:
var tmpEvent = new Google.Apis.Calendar.v3.Data.Event
{
Description = Event.Description + "---attendees updated---",
};
//don't send the notification to anyone
//all attendees will get the notification when we resave the event with the original description
var patchRequest = service.Events.Patch(tmpEvent, GOOGLE_PRIMARY_CALENDARID, ExternalID);
patchRequest.SendUpdates = EventsResource.PatchRequest.SendUpdatesEnum.None;
await patchRequest.ExecuteAsync().ConfigureAwait(false);对于补丁,将SendUpdates设置为None意味着与会者不会收到有关更改的通知,因此所有日历事件都将以静默方式更新。
最后,我保存整个活动(带有适当的描述和参与者),并将更新发送给所有参与者:
var tmpEvent = new Google.Apis.Calendar.v3.Data.Event
{
Id = ExternalID == null ? Convert.ToString(Event.ID) : ExternalID,
Start = new EventDateTime
{
DateTime = Event.StartDate,
TimeZone = GetGoogleTimeZoneFromSystemTimeZone(timeZoneInfo.Id)
},
End = new EventDateTime
{
DateTime = Event.EndDate,
TimeZone = GetGoogleTimeZoneFromSystemTimeZone(timeZoneInfo.Id)
},
Summary = Event.Title,
Description = Event.Description,
Attendees = attendees.Select(a => new EventAttendee
{
Email = a.Value,
ResponseStatus = "accepted"
}).ToList(),
GuestsCanInviteOthers = false,
Location = Event.Location
};
var updateRequest = service.Events.Update(tmpEvent, GOOGLE_PRIMARY_CALENDARID, ExternalID);
updateRequest.SendUpdates = EventsResource.UpdateRequest.SendUpdatesEnum.All;
savedEvent = await updateRequest.ExecuteAsync().ConfigureAwait(false);这并不理想,因为它需要两次调用Google的API才能正确地保存与会者,但从好的方面来看,与会者只会收到一次更改通知。
https://stackoverflow.com/questions/62196828
复制相似问题