列出使用REST API从Office 365 OneDrive(Sharepoint)中用于商业和教育的“与我共享"文件夹的文件夹内容吗?

问题描述:

是否可以从Office 365(Sharepoint)REST API获取与我共享"文件夹的内容?

Is there a way to get the contents of the 'Shared with Me' folder from the Office 365 (Sharepoint) REST api ?

我在api参考中看不到与此相关的任何内容. https://msdn.microsoft.com/office/office365/APi/files -rest-operations

I can't see anything in the api reference reagrding this. https://msdn.microsoft.com/office/office365/APi/files-rest-operations

找到了解决方案...

Found the solution to this...

必须使用sharepoint搜索api而不是使用文件api. 以下带有KQL查询参数的端点可用于获取与我共享的文件"列表

Instead of using the files api you must use the sharepoint search api. The following endpoint with the KQL query parameters can be used to get a list of files 'shared with me'

https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(SharedWithUsersOWSUSER:{UserAccountName} AND contentclass:STS_ListItem_MySiteDocumentLibrary)'

以上内容将获取与我共享"的文件列表,但不会显示共享文件夹中的任何文件.要在共享文件夹中获取项目,可以使用以下端点.

This above will get a list of files 'shared with me' but not anything inside a shared folder. To get the items inside a shared folder you can use the following endpoint.

https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(ParentLink:{ParentLink})'

确保父链接是url编码的.您可以从文件夹属性中检索父链接.

Make sure the parent link is url encoded. You can retrieve the parent link from the folder properties.

最后要获得在第一个请求中使用的帐户名,您可以向sharepoint webs api进行请求.

Finally to get the account name used in the first request you can make a request to the sharepoint webs api.

https://{tenant}-my.sharepoint.com/_api/web/CurrentUser