outlook - 未收到包含自定义属性的日历事件的更改通知
问题描述
我们希望从用户的 Outlook 日历中接收更改通知。我们希望将这些通知限制为仅包含我们自定义属性的日历项。
创建日历事件的代码
private static async Task<Event> CreateAppointmentAsync(GraphServiceClient graphClient)
{
var newEvent = new Microsoft.Graph.Event
{
Subject = "Test Calendar Appointmnt",
Start = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T21:00:00" },
End = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T22:00:00" },
Location = new Location() { DisplayName = "Somewhere" },
Body = new ItemBody { Content = "Some Random Text" },
};
Microsoft.Graph.Event addedEvent;
try
{
newEvent.SingleValueExtendedProperties = new EventSingleValueExtendedPropertiesCollectionPage();
newEvent.SingleValueExtendedProperties.Add(new SingleValueLegacyExtendedProperty { Id = "String {00020329-0000-0000-C000-000000000046} Name CompanyID", Value = "12345" });
addedEvent = await graphClient.Me.Calendar.Events.Request().AddAsync(newEvent);
}
catch (Exception e)
{
throw e;
}
return addedEvent;
}
订阅代码片段
var subscription = new Subscription
{
ChangeType = "created",
NotificationUrl ="<OUR-URL>",
Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
ClientState = "custom_data_state",
LatestSupportedTlsVersion = "v1_2"
};
订阅已成功创建,但不会为包含上述特定自定义属性的项目发送通知。
解决方案
事实证明我只是在捕获“创建”通知。我忽略了添加“更新”和“删除”。
我正在测试我日历中已经存在的事件。没有触发任何事件,因为我没有创建订阅来检测更新和删除。
这是更正后的订阅:
var subscription = new Subscription
{
ChangeType = "created,updated,deleted",
NotificationUrl ="<OUR-URL>",
Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
ClientState = "custom_data_state",
LatestSupportedTlsVersion = "v1_2"
};
推荐阅读
- reactjs - 材料 ui 文本字段类型日期,最小值不起作用
- javascript - Cant' access async nested json in state,得到“TypeError:无法读取未定义的属性'XX'”的错误
- c# - 仅将 SignalR 用于用户会话
- php - 如何停止暴力攻击以保护文件夹内的文档安全?
- ubuntu - 如何确保 Livenes/Readiness 探测使用 http 而不是 https 完成
- apache-kafka - 使用消息时的 Apache Kafka 清理
- angular - Angular:如何根据验证器正确查找和添加类到角度元素
- javascript - 向 Vue 实例的销毁钩子添加回调
- visual-studio - 无法在具有 Anaconda 环境的 VS Code 中为 Plotly Dash 运行本地服务器
- python - 使用 librosa 理解 STFT