Microsoft图形可恢复上传URL返回V2 OneDrive API上传URL [英] Microsoft Graph Resumable Upload URL Returning V2 OneDrive API Upload URL
问题描述
我正在尝试使用Microsoft Graph API通过REST调用创建可恢复的上载,并且我可以收到一个上载URL.但是,它根本不像文档URL,似乎是旧"非Graph v2.0 API
I am attempting to use Microsoft Graph API to create a resumable upload through a REST call and I can receive a upload URL in return. However, it's not at all like the documentation URL and seems to be an "older" non-Graph v2.0 API
https://dev.onedrive.com/items/upload_large_files.htm
在此示例中,返回URL为
In the example the return URL is
https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337
但是,我收到的是:
https://{server}/_api/v2.0/drive/items/01LFLHCDPPDY5LDTR3UREILVK4ISP2HJIE/uploadSession?guid='031a05ef-806e-4118-a5ff-8dea9b558c3e'&path='~tmp8B_test.xls'&overwrite=True&rename=False
与OneDrive API的差异一致. https://dev.onedrive.com/direct-endpoint-differences.htm
Which is consistent with the OneDrive API differences. https://dev.onedrive.com/direct-endpoint-differences.htm
但是会导致401未经授权的响应,错误为
But results in a 401 Unauthorized response with an error of
类型异常 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' 被扔了."
Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."
我认为这是因为,当我在标题中放入"Authorization:Bearer {accesstoken}"时,身份验证是不同的,并且我的MS-Graph访问令牌无效(该标题适用于所有我通过Graph进行的其他REST调用)
I think this is because the authentication is different and my MS-Graph access token is not valid when I put 'Authorization: Bearer {accesstoken}' in the header (that header works for all of my other REST calls via Graph)
如何获取图表上传URL来将文件上传到OneDrive Business ?或者如何使返回URL正常工作,以便我可以上传到OneDrive业务?
修改:显示权限
这是我从app.developers获得的权限
here's my permissions from the app.developers
这是我创建访问令牌的地方
And here's where I create the access token
request.setEndpoint('https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token');
request.setHeader('Content-Type', 'application/x-www-form-urlencoded');
string body;
body = '&client_id={clientId}';
body += '&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default';
body += '&client_secret={Secret}';
body += '&grant_type=client_credentials';
在此处为上载会话进行API调用(不考虑语法):
webRequest.setEndPoint('https://graph.microsoft.com/v1.0/users/{myUserId}/drive/items/{parentItem_folder_Id}:/test.xls:/createUploadSession');
webRequest.setHeader('Authorization', 'Bearer ' + getAccessToken());
webRequest.setHeader('Content-Type', 'application/json');
webRequest.setHeader('Accept', 'application/json');
webRequest.setHeader('Host', 'graph.microsoft.com');
webRequest.setHeader('Content-Length', '0');
webRequest.setMethod('POST');
推荐答案
我相信这里的问题是您试图在没有用户的情况下使用文件上传(即,仅应用程序而不是委派场景).当您请求正确的作用域(Files.ReadWrite.All
)时,当前不支持此方案.从文档:
I believe the problem here is that you're attempting to upload files using without a user (i.e. an app-only rather than delegated scenario). While you're requesting the correct scope (Files.ReadWrite.All
), this scenario is not currently supported. From the documentation:
注意:此API尚不支持Files.ReadWrite.All应用程序权限.计划很快提供全力支持.
Note: The Files.ReadWrite.All application permission is not yet supported on this API. Full support is planned soon.
目前,仅在委派情况下(例如,用户已直接通过身份验证并正在上传到自己的驱动器),才支持断点续传.
At the moment, resumable uploads are only supported in delegated scenarios (i.e. where a user has directly authenticated and is uploading to their own drive).
这篇关于Microsoft图形可恢复上传URL返回V2 OneDrive API上传URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!