【发布时间】:2017-07-19 18:03:24
【问题描述】:
我正在尝试使用 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' 被扔了。”
我认为这是因为身份验证不同,并且当我将“Authorization: Bearer {accesstoken}”放在标头中时,我的 MS-Graph 访问令牌无效(该标头适用于所有我通过 Graph 进行的其他 REST 调用)
如何获取图表上传 URL 以将我的文件上传到 OneDrive Business?或者如何让返回 URL 起作用,以便上传到 OneDrive Business?
编辑:显示权限
这里是我创建访问令牌的地方
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');
【问题讨论】:
-
您能说明一下您的环境吗?您是在尝试使用 Microsoft Graph 创建可恢复的上传会话还是在使用 OneDrive API?这是两个独立的 API,您调用它们的方式也不同。另外,您使用的是纯 REST 还是 .NET SDK?
-
感谢您的跟进。为了清楚起见,我编辑了我的问题。这是使用纯 REST 调用创建可恢复上传的 Graph API。我的偏好是尽可能多地使用 Graph
-
我还添加了令牌刷新代码(适用于所有其他 REST 调用)和来自 apps.dev.microsoft.com 的权限
-
我在发现这个问题上取得了一些进展,但它并没有解决问题:stackoverflow.com/questions/43656203/…
-
您能否添加您正在发出的 HTTP 调用以请求上传 URI?它可能会有所帮助。
标签: onedrive sharepoint-api microsoft-graph-api