【发布时间】:2023-02-20 23:18:46
【问题描述】:
在将请求复制到 MS Graph 后,我需要获取一个 driveItem。据我了解,我需要处理请求标头Location,以根据documentation获取用于监控复制过程的url。
此外,我正在使用 AsyncMonitor<DriveItem> 和任务 PollForOperationCompletionAsync。
但是在复制结束时,我收到了authorization error: Invalid Audience的错误
我想我收到此错误是因为 asyncMonitor 在成功复制后将我重定向到 resourceUrl,这是一个 SharePoint REST API 端点:https://{tenant-name}.sharepoint.com/_api/v2.0/drives/{drive-id}/items/{driveItem}
如果我的方法是正确的,那么请解释为什么我从共享服务 API使用时微软图形 API.因此我需要兑换代币等
我的代码:
var copyResponse = await client.Sites[siteId].Lists[listId].Drive.Items[file.DriveItemId]
.Copy(file.Name, reference)
.Request()
.PostResponseAsync();
var locationHeader = copyResponse.HttpHeaders.Location;
if (locationHeader == null)
{
return null;
}
if (!locationHeader.IsAbsoluteUri)
{
locationHeader = new Uri(client.BaseUrl + locationHeader.OriginalString);
}
IProgress<AsyncOperationStatus> progress = new Progress<AsyncOperationStatus>(operationStatus =>
{
logger.LogInformation(
$"Copying file {file.Name} status: {operationStatus.Status}");
});
var asyncMonitor = new AsyncMonitor<DriveItem>(client, locationHeader.AbsoluteUri);
var result = await asyncMonitor.PollForOperationCompletionAsync(progress, CancellationToken.None);
【问题讨论】: