有没有办法获取共享文件的权限 – OneDrive?

huangapple go评论88阅读模式
英文:

Is there any way to get the permissions from a shared file - OneDrive?

问题

如何使用GraphAPI获取OneDrive上与我共享的文件的权限详细信息?

我尝试了以下代码,但权限值为null。

IDriveSharedWithMeCollectionPage driveItems = await graphClient.Me.Drive.SharedWithMe().Request(requestOptions)
            .WithUserAccount(ClaimsPrincipal.Current.ToGraphUserAccount())
            .GetAsync();

是否有一种方法可以使用GraphAPI从我的共享文件中获取权限详细信息,如读/写或只读?

权限显示在OneDrive的管理访问选项中,但如何通过API获取详细信息?
是否可能通过使用这样的API获取这些数据?

英文:

How do I get the permission details of files shared with me on OneDrive using GraphAPI?

I tried the following code but the permission values are null.

IDriveSharedWithMeCollectionPage driveItems = await graphClient.Me.Drive.SharedWithMe().Request(requestOptions)
            .WithUserAccount(ClaimsPrincipal.Current.ToGraphUserAccount())
            .GetAsync();

Is there any way to get the permission details like read/write or readonly by using the GraphAPI from my shared Files?

The permissions are showing in the OneDrive at the Manage Access option but how do I get the details by using an API ?
Is it possible to get those data by using such an API?

答案1

得分: 1

我还没有尝试过,但我猜权限是针对驱动项目的,只有在获取驱动项目后才能获得它。您可以按以下方式获取共享项目:

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var sharedWithMe = await graphClient.Me.Drive
    .SharedWithMe()
    .Request()
    .GetAsync();

然后:

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var permissions = await graphClient.Me.Drive.Items["{item-id}"].Permissions
    .Request()
    .GetAsync();

DriveItem的权限关系不能在获取DriveItem或DriveItems集合的调用中展开。您必须直接访问权限属性。

DriveItem的有效共享权限可以来自两个来源:

  • 直接应用于DriveItem本身的共享权限。

  • 继承自DriveItem祖先的共享权限。

附加参考:

https://learn.microsoft.com/en-us/graph/api/driveitem-list-permissions?view=graph-rest-1.0&tabs=http

希望能有所帮助。

英文:

I haven't tried it but i am guessing that permissions are specific to the drive item which you can get it after fetching it only.You can get shared item like below:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var sharedWithMe = await graphClient.Me.Drive
	.SharedWithMe()
	.Request()
	.GetAsync();

and then :

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var permissions = await graphClient.Me.Drive.Items["{item-id}"].Permissions
	.Request()
	.GetAsync();

The permissions relationship of DriveItem cannot be expanded as part of a call to get DriveItem or a collection of DriveItems. You must access the permissions property directly.

Effective sharing permissions of a DriveItem can come from two sources:

  • Sharing permissions applied directly on the DriveItem itself.

  • Sharing permissions inherited from the DriveItem's ancestors.

Additional reference:

https://learn.microsoft.com/en-us/graph/api/driveitem-list-permissions?view=graph-rest-1.0&tabs=http

Hope it helps.

huangapple
  • 本文由 发表于 2020年1月6日 21:12:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612767.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定