使用 MS graph SDK 订阅文件夹

Subscribe to a folder with MS graph SDK

我如何才能使用只能订阅一个文件夹的 Microsoft Graph SDK(.Net 和 C#)? (我想基于此编写一个 webhook)。

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 = "/drives/{driveID}/root/";
      sub.ExpirationDateTime = DateTime.UtcNow.AddMinutes(5);
      sub.ClientState = "SecretClientState";

      var newSubscription = await graphServiceClient.Subscriptions.Request().AddAsync(sub);

到目前为止,我只能订阅根目录中的所有内容,而不能订阅 Onedrive 中的特定文件夹。

是的,在个人 OneDrive 中,您可以订阅 root folder 或该驱动器中的任何 subfolder,但在 OneDrive 中,对于企业,您只能订阅 root folder。如果您需要进一步的帮助,请告诉我。

Note: You cannot subscribe to drive or driveItem instances that are not folders, such as individual files. You could refer to our official document here.

所以您可以在根目录中创建文件夹,在这种情况下,您可以允许您的用户创建他们可以上传文件的文件夹。

希望对您有所帮助