Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OneDrive 2.0下载文件内容401 HTTP代码_C#_Onedrive - Fatal编程技术网

C# OneDrive 2.0下载文件内容401 HTTP代码

C# OneDrive 2.0下载文件内容401 HTTP代码,c#,onedrive,C#,Onedrive,我创建了一个Azure AD应用程序,该应用程序使用应用程序权限对OneDrive API具有完全访问权限(R&W)。(我的应用程序是守护程序应用程序。)这些权限已授予并批准 HTTP GET https://{MyTenant}.sharepoint.com/_api/v2.0/drives//root://Document.docx 返回200,内容包含关于文件的JSON信息 获取2016-12-24T14:15:31.458请求的uri: https://{MyTenant}.share

我创建了一个Azure AD应用程序,该应用程序使用应用程序权限对OneDrive API具有完全访问权限(R&W)。(我的应用程序是守护程序应用程序。)这些权限已授予并批准

HTTP GET https://{MyTenant}.sharepoint.com/_api/v2.0/drives//root://Document.docx
返回200,内容包含关于文件的JSON信息

获取2016-12-24T14:15:31.458请求的uri:

https://{MyTenant}.sharepoint.com/_api/v2.0/drives//root://Document.docx:/content

2016-12-24T14:15:31.888 StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { X-SharePointHealthScore: 0 SPRequestGuid: c935c49d-a0fa-3000-a357-32b18090ecd4 request-id: c935c49d-a0fa-3000-a357-32b18090ecd4 Strict-Transport-Security: max-age=31536000 X-FRAME-OPTIONS: SAMEORIGIN SPRequestDuration: 140 SPIisLatency: 1 MicrosoftSharePointTeamServices: 16.0.0.6008 X-Content-Type-Options: nosniff X-MS-InvokeApp: 1; RequireReadOnly Cache-Control: private Date: Sat, 24 Dec 2016 14:15:31 GMT P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI" Server: Microsoft-IIS/8.5 WWW-Authenticate: NTLM X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 16 Content-Type: text/plain; charset=utf-8 } 2016-12-24T14:15:31.888 401 UNAUTHORIZED
我正确地添加了授权标头。我创建了一个上传功能,它将文件发送到同一个文档库,并且可以正常工作,与删除功能相同

仅当请求文件的/内容时,此401的原因是什么?我如何解决这个问题

我将JWT令牌加载到JWT.io中:它具有以下角色:“角色”:
[“TermStore.ReadWrite.All”、“Sites.Manage.All”、“TermStore.Read.All”、“Sites.ReadWrite.All”、“Sites.FullControl.All”]
这里发生了什么?请求的URI为:
https://.sharepoint.com/_api/v2.0/drives//root:/faas.‌​pptx:/content

当使用两种类型的GET请求GET/drive/items/{item id}/content
GET/drive/root:/{path and filename}:/content->return 401 Unauthorized

致以最良好的祝愿


Jens

不幸的是,对于OneDrive for Business和“仅应用程序”场景,这是一个长期存在的问题。您可以在上跟踪此问题。

谢谢您的回复。在尝试使用SharePoint REST API下载文件时,我首先检索了weburl:https://{myTenantName}.SharePoint.com/_layouts/15/WopiFrame.aspx?sourcedoc=%7BB2CE1848-1ff6-4db7c-B0D9-B4DB8D08D910%7D&file=faas.pptx&action=default执行对以下资源的访问是否正确:https://{myTenantName}.sharepoint.com/_api/web/GetFileByServerRelativeUrl('faas.pptx')/$value文件位于租户根文件夹中的文档库中。没关系。我通过探索SharePoint API找到了正确的语法。感谢@Brad为我指明了正确的方向!