我正在尝试使用Graph订阅API在One Drive中捕获“文档共享”事件。我可以在Dotnet WebAPI应用程序中创建订阅。以下是我的代码:
Microsoft.Graph.User user = funGetO365User("user1@mydomain.onmicrosoft.com");
//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);
我的应用程序在本地主机上运行,并且我正在使用ngrok将请求中继到本地主机。
创建订阅后,我确实会收到通知:
[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
}
}
但是,如果我对用户的一个驱动器(编辑文档,共享文档)进行了任何更改,则不会收到任何通知。
有什么想法我只需要收到通知就需要做什么?
答案 0 :(得分:0)
问题似乎已解决。端点网址
"graph.microsoft.com/v1.0/drives" + user.Id + "/root"
其中user.Id是图形用户唯一ID。我现在可以接收任何更改的通知,但是想知道是否有一种方法可以仅在任何驱动器文件的权限发生更改时才得到通知?