如何为 Graph API 的特定事件创建订阅

How to create subscription for specific event of Graph API

我想收到有关我从我的应用程序创建的特定事件的通知。为此,我使用以下代码订阅特定事件。

 var subscription = new Subscription
                {
                    ChangeType = "updated,deleted",
                    NotificationUrl = $"{_notificationHost}/listen",
                    Resource = "me/events/{event-id}",
                    ClientState = Guid.NewGuid().ToString(),
                    IncludeResourceData = false,
                    // Subscription only lasts for one hour
                    ExpirationDateTime = DateTimeOffset.UtcNow.AddHours(1)
                };

但是在创建时抛出异常:

Error creating subscription: Code: ExtensionError Message: Operation: Create; Exception: [Status Code: BadRequest; Reason: The value 'https://outlook.office365.com/api/beta/Users('{userid}')/Events('{event-id}')' of parameter 'Resource' is not supported.]

只是 运行 进入同一问题。看起来订阅 API 不支持订阅特定事件,只支持整个日历。 "Resources examples" section 中有一个订阅事件的示例,它看起来正是您想要的:me/events。 updated/deleted事件的ID包含在回调中,所以如果你只关心某些事件,你可以使用它。