更改 Sharepoint Webhook 的 Microsoft Graph 资源
Change Microsoft Graph Resource for Sharepoint Webhook
我目前正在使用 C# .Net Core 编写 Microsoft Graph 教程,在此过程中我遇到了以下 C# 订阅方法:
[HttpGet]
public async Task<ActionResult<string>> Get()
{
var graphServiceClient = GetGraphClient();
var sub = new Microsoft.Graph.Subscription();
sub.ChangeType = "updated";
sub.NotificationUrl = config.Ngrok + "/api/notifications";
sub.Resource = "/users";
sub.ExpirationDateTime = DateTime.UtcNow.AddMinutes(15);
sub.ClientState = "SecretClientState";
var newSubscription = await graphServiceClient
.Subscriptions
.Request()
.AddAsync(sub);
Subscriptions[newSubscription.Id] = newSubscription;
if (subscriptionTimer == null)
{
subscriptionTimer = new Timer(CheckSubscriptions, null, 5000, 15000);
}
return $"Subscribed. Id: {newSubscription.Id}, Expiration: {newSubscription.ExpirationDateTime}";
}
并想知道如何为共享点列表而不是用户更改它。
如果我将其更改为 /sites/{site-id} 或类似名称,则它不起作用。 (参见 sub.Resource)
Github-Link: MS Repo
我自己通过 sub.Resource 找到了解决方案:/sites/{site-id}/lists/{list-id}
Microsoft Graph API 使用 webhook 机制向客户端发送更改通知。使用 Microsoft Graph API,应用程序可以订阅 SharePoint 网站下列表的更改。
资源路径 - 列表中内容的更改:
/sites/{id}/lists/{id}
有关如何订阅和处理传入通知的详细信息,请参阅Set up notifications for changes in user data
还要确保您在此处勾选了必要的permissions。
我目前正在使用 C# .Net Core 编写 Microsoft Graph 教程,在此过程中我遇到了以下 C# 订阅方法:
[HttpGet]
public async Task<ActionResult<string>> Get()
{
var graphServiceClient = GetGraphClient();
var sub = new Microsoft.Graph.Subscription();
sub.ChangeType = "updated";
sub.NotificationUrl = config.Ngrok + "/api/notifications";
sub.Resource = "/users";
sub.ExpirationDateTime = DateTime.UtcNow.AddMinutes(15);
sub.ClientState = "SecretClientState";
var newSubscription = await graphServiceClient
.Subscriptions
.Request()
.AddAsync(sub);
Subscriptions[newSubscription.Id] = newSubscription;
if (subscriptionTimer == null)
{
subscriptionTimer = new Timer(CheckSubscriptions, null, 5000, 15000);
}
return $"Subscribed. Id: {newSubscription.Id}, Expiration: {newSubscription.ExpirationDateTime}";
}
并想知道如何为共享点列表而不是用户更改它。
如果我将其更改为 /sites/{site-id} 或类似名称,则它不起作用。 (参见 sub.Resource)
Github-Link: MS Repo
我自己通过 sub.Resource 找到了解决方案:/sites/{site-id}/lists/{list-id}
Microsoft Graph API 使用 webhook 机制向客户端发送更改通知。使用 Microsoft Graph API,应用程序可以订阅 SharePoint 网站下列表的更改。
资源路径 - 列表中内容的更改: /sites/{id}/lists/{id}
有关如何订阅和处理传入通知的详细信息,请参阅Set up notifications for changes in user data
还要确保您在此处勾选了必要的permissions。