c# - Graph SDK 中的订​​阅通知

标签 c# microsoft-graph-api

我目前正在使用 Graph SDK 实现 Webhook,但遇到了一些小问题/不便。我正在订阅这样的用户资源的日历事件:

var request = GraphClientInitializer.Instance.GraphClient.Subscriptions.Request();
var result = await request.AddAsync(
                    new Subscription
                    {
                        ChangeType = WebhookConsts.SubscriptionChangeType,
                        NotificationUrl = WebhookConsts.SubscriptionNotificationUrl,
                        Resource = "/users/" + UserMail + "/" + "events",
                        ExpirationDateTime = DateTimeOffset.Now.AddMinutes(20),
                        ClientState = WebhookConsts.SubscriptionIdentifier
                    }
                    );

我收到通知,我可以读取发送到通知 url 的消息,但 SDK 中似乎没有一个对象可以解析收到的通知。

目前我自己做:

public class Notification
{
    [JsonProperty("value")]
    public List<NotificationValue> Values { get; set; }
}

public class NotificationValue
{
    [JsonProperty("subscriptionId")]
    public String SubscriptionId { get; set; }

    [JsonProperty("subscriptionExpirationDateTime")]
    public String SubscriptionExpirationDateTime { get; set; }

    [JsonProperty("clientState")]
    public String ClientState { get; set; }

    [JsonProperty("changeType")]
    public String ChangeType { get; set; }

    [JsonProperty("resource")]
    public String Resource { get; set; }

    [JsonProperty("resourceData")]
    public NotificationResourceData ResourceData { get; set; }
}

public class NotificationResourceData
{
    [JsonProperty("@odata.type")]
    public String ODataType { get; set; }

    [JsonProperty("@odata.id")]
    public String ODataId { get; set; }

    [JsonProperty("odata.etag")]
    public String ODataEtag { get; set; }

    [JsonProperty("Id")]
    public String Id { get; set; }
}

是否有一个对象我可以用于这个或我可以在 Graph SDK 中实现它的任何其他方式。

最佳答案

更新:此功能已在 PR #1053 中实现现在可以通过类 ChangeNotificationCollection 获得.

enter image description here

关于c# - Graph SDK 中的订​​阅通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49534591/

相关文章:

c# - XMlSerialization 没有序列化 Datetime

c# - Object.ReferenceEquals 的行为不符合预期

c# - 如何在C#中将字符串转换为int数组

microsoft-graph-api - 删除事件发生时从 Microsoft Graph 获取通知

azure - 使用 AAD Graph API 或 Microsoft Graph API 获取 Azure Active Directory 应用程序权限

c# - 使用 Graph API 时出现 "The tenant for tenant guid does not exist"- 用户类型为成员(member)的事件

c# - WCF 中继已连接到监听器,但没有连接监听器?

microsoft-graph-api - 为 OneDrive Business 创建订阅返回 403 禁止

java - 微软图形API : A question about IDriveItemCollectionPage

c# - 32 位 Windows 服务写入 64 位注册表。 (AutoAdminLogon 键)