C# 如何使用RESTAPI在OneDrive for Business上下载共享文件?

C# 如何使用RESTAPI在OneDrive for Business上下载共享文件?,c#,rest,onedrive,C#,Rest,Onedrive,我正在尝试从OneDrive for Business的“与我共享”文件夹中显示的共享文件夹下载文件。我正在使用以下REST调用获取文件夹名称和其中显示的文件: https://{tenant}-my.sharepoint.com/_-api/search/query?querytext='(SharedWithUsersOWSUSER:{UserAccountName}和contentclass:STS_ListItem_MySiteDocumentLibrary) 及 https://{te

我正在尝试从OneDrive for Business的“与我共享”文件夹中显示的共享文件夹下载文件。我正在使用以下REST调用获取文件夹名称和其中显示的文件:

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

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

没有问题。从这些调用提供的元数据中,我获取每个目录中的文件,并尝试使用以下get请求调用下载它们(注意,“user1”是下载文件的人,“user2”是共享文件的人):

https://{tenant}-my.sharepoint.com/personal/user1_mydomain_com/_api/Web/GetFileByServerRelativeUrl('/personal/user2_mydomain_com/Documents/test/test1.docx')/$value

https://{tenant}-my.sharepoint.com/\u api/v1.0/user2\u mydomain\u com/files/{fileid}

我还尝试使用新的v2.0调用,但它们似乎还不支持“与我共享”文件夹/文件访问

在我所有的尝试中,我在尝试下载共享文件时都会遇到“错误请求”或“未找到”错误。我使用以下REST调用下载自己的OneDrive for Business文件时没有问题:

https://{tenant}-my.sharepoint.com/personal/user\u mydomain\u com/\u api/Web/GetFileByServerRelativeUrl('/personal/user\u mydomain\u com/Documents/user Folder/Test.htm')/$value

我使用的电话来自:

(v1.0版呼叫)

(v2.0调用)


如有任何建议,将不胜感激。谢谢

我还尝试通过SharePoint客户端方法下载该文件:var file=await sharePointClient.Files.GetByPathAsync(“/personal/user2\u mydomain\u com/Documents/test/test1.docx”);这只是给了我一个“未找到资源”错误。我还尝试通过SharePoint客户端方法下载该文件:var file=wait sharePointClient.Files.GetByPathAsync(“/personal/user2_mydomain_com/Documents/test/test1.docx”);这只是给了我一个“未找到资源”错误。我还尝试通过SharePoint客户端方法下载该文件:var file=wait sharePointClient.Files.GetByPathAsync(“/personal/user2_mydomain_com/Documents/test/test1.docx”);这只会给我一个“未找到资源”错误。