图形API Webhook订阅OneDrive无法正常工作

问题描述 投票:0回答:1

我正在尝试使用Graph订阅API在One Drive中捕获“文档共享”事件。我能够在我的Dotnet WebAPI应用程序中创建订阅。以下是我的代码:

     Microsoft.Graph.User user = funGetO365User("[email protected]");

//Notification  URL = /notification/listen

                Subscription subscription = new Subscription
                {
                    Resource = "/"+ user.Id + "/drive/root",
                    ChangeType = "updated",
                    NotificationUrl = 
 ConfigurationManager.AppSettings["ida:NotificationUrl"],
                    ClientState = Guid.NewGuid().ToString(),
                    //ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 4230, 0) // current maximum timespan 
                    ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 15, 0) // shorter duration useful for testing
                };

 string contentString = JsonConvert.SerializeObject(subscription, 
                new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, subscriptionsEndpoint);
            request.Content = new StringContent(contentString, System.Text.Encoding.UTF8, "application/json");

 // Send the `POST subscriptions` request and parse the response.
 GraphHttpClient graphHttpClient = new GraphHttpClient(accessToken);
 HttpResponseMessage response = await graphHttpClient.SendAsync(request);

我的应用程序在localhost上运行,我正在使用ngrok将请求中继到localhost。

创建订阅后,我会收到通知:

[HttpPost]
public async Task<ActionResult> Listen()
{

    // Validate the new subscription by sending the token back to Microsoft Graph.
    // This response is required for each subscription.
    if (Request.QueryString["validationToken"] != null)
    {
        var token = Request.QueryString["validationToken"];

        return Content(token, "plain/text");
    }
    else
    {
    // My code- Never executed
    }
}

但是,如果我对用户的一个驱动器(编辑文档,共享文档)进行任何更改,我没有收到任何通知。

知道我只需要收到通知我需要做什么吗?

microsoft-graph webhooks onedrive azure-ad-graph-api
1个回答
0
投票

这个问题似乎得到了解决。端点URL

"graph.microsoft.com/v1.0/drives" + user.Id + "/root" 

其中user.Id是Graph用户唯一ID。我现在能够接收任何更改的通知,但是想知道是否有一种方法只有在任何驱动器文件的权限发生更改时才能收到通知?

© www.soinside.com 2019 - 2024. All rights reserved.