首页 文章

Microsoft Graph Resumable Upload URL返回V2 OneDrive API上传URL

提问于
浏览
0

我试图使用Microsoft Graph API通过REST调用创建可恢复的上传,我可以收到一个上传URL作为回报 . 但是,它根本不像文档URL,似乎是一个“较旧的”非Graph v2.0 API

https://dev.onedrive.com/items/upload_large_files.htm

在示例中,返回URL是

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

但导致401 Unauthorized响应,错误为

抛出了“Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException”类型的异常 . “

我认为这是因为身份验证不同,当我在 Headers 中放入'Authorization: Bearer '时,我的MS-Graph访问令牌无效(该 Headers 适用于我通过Graph进行的所有其他REST调用)

How can I get a Graph Upload URL to upload my file to OneDrive Business ?还是 how can I get the return URL to work so I can upload to OneDrive Business

Edit :表示允许

这是app.developers的权限
enter image description here

这是我创建访问令牌的地方

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';

Here is where I'm making the API call for the upload session (无视语法):

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');

2 回答

  • 1

    我相信这里的问题是你要求正确的范围( Files.ReadWrite.All ),目前不支持这种情况 . 来自documentation

    注意:此API尚不支持Files.ReadWrite.All应用程序权限 . 计划很快得到全力支持 .

    目前,仅在委派的场景中支持可恢复的上载(即,用户已经直接认证并且正在上载到他们自己的驱动器的位置) .

  • 1

    尝试使用创建上载会话后返回的URL时,使用“授权:承载”标头会导致401错误 . 删除授权标头后,您可能仍会收到错误消息 . 对我来说这是403 Forbidden错误 .

相关问题