sharepoint - Ms Graph API Onedrive 副本返回 generalException
问题描述
我使用 Ms Graph API 开发了一个 webapp,将文件从共享点库复制到其他共享点库(全部在线)。
我这样调用 Graph API 副本:
POST https://graph.microsoft.com/v1.0/drives/SrcDriveID/items/*SrcDriveItem*/copy?@microsoft.graph.conflictBehavior=replace
{ "parentReference" : { "driveId": "*DestDriveID*", "id": "*DestParentDriveItem*" }, "@microsoft.graph.conflictBehavior":"replace" } }
我收到以下错误:
<Internal Server Error> <{"error": {"code": "generalException","message": "An unspecified error has occurred.","innerError": {"request-id": "0623069a-7071-47f9-be92-48d58902f300","date": "2020-05-06T21:11:07"}}}>
webapp 正在使用委派权限,并且仅使用工作帐户。授予此应用程序的 Graph API 授权是:
- 目录.read.all
- 文件读写
- Sites.Read.All
- 用户读
- File.ReadWrite.All
这个问题在我的生产环境中是系统性的。尽管权限相同,但我的开发环境中没有它。触发 webapp(和相关的承载密钥)的用户对源和目标共享点库具有读/写访问权限。在目的地,他们是成员而不是所有者。
欢迎任何帮助!
提前致谢
更新:添加 .NET C# 代码:
StringBuilder jsonData = new StringBuilder("{ \"parentReference\" : { \"driveId\": \"" + DestDriveID + "\", \"id\": \"" + DestParentDriveItem + "\" }, \"@microsoft.graph.conflictBehavior\":\"replace\" } }");
String restCallUrl;
if (overwrite)
{
restCallUrl = _baseUri + "drives/" + SrcDriveID + "/items/" + SrcDriveItem + "/copy?@microsoft.graph.conflictBehavior=replace";
}
else
{
restCallUrl = _baseUri + "drives/" + SrcDriveID + "/items/" + SrcDriveItem + "/copy";
}
HttpClient apiCallClient = new HttpClient();
HttpRequestMessage apiRequest = new HttpRequestMessage(HttpMethod.Post, restCallUrl);
apiRequest.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpContent addAttachmentBody = new StringContent(jsonData.ToString(), Encoding.UTF8, "application/json");
apiRequest.Content = addAttachmentBody;
apiRequest.Headers.Add("Authorization", "Bearer " + _accessToken);
HttpResponseMessage apiCallResponse = await apiCallClient.SendAsync(apiRequest);
if (apiCallResponse.StatusCode != System.Net.HttpStatusCode.Accepted)
{
String requestResponse = await apiCallResponse.Content.ReadAsStringAsync();
_mylog.Warning("Copy -<" + apiCallResponse.ReasonPhrase + "> <" + requestResponse + ">");
throw new DllNotFoundException();
}
更新 我意识到 jsonData 不平衡。我纠正以下内容:
StringBuilder jsonData = new StringBuilder("{ \"parentReference\" : { \"driveId\": \"" + DestDriveID + "\", \"id\": \"" + DestParentDriveItem + "\" }, \"@microsoft.graph.conflictBehavior\":\"replace\", \"name \": \"" + DstFileName + "\" }");
或者
StringBuilder jsonData = new StringBuilder("{ \"parentReference\" : { \"driveId\": \"" + DestDriveID + "\", \"id\": \"" + DestParentDriveItem + "\" }, \"@microsoft.graph.conflictBehavior\":\"replace\" }");
两者都因相同的错误而失败。
最后一个给了我:
Copy -<Internal Server Error> <{"error": {"code": "generalException","message": "An unspecified error has occurred.","innerError": {"request-id": "ebf30e17-b4be-4994-bf86-bc3b86834d12","date": "2020-05-09T07:30:42"}}}>
更新:我在 Graph explorer 上做了完全相同的操作,它确实有效
https://graph.microsoft.com/v1.0/drives/b!fffffffffqv/items/01GEGKyyyyyyuuHR/copy?@microsoft.graph.conflictBehavior=replace
{ "driveId": "b!yyyyy", "id": "uuuuuu" }, "@microsoft.graph.conflictBehavior":"replace" }
设置 File.ReadWrite 和 Files.ReadWrite.All 后,它就可以与 Graph API Explorer 一起使用。我会仔细检查它们是否应用于我的 web 应用程序。 UPDATE Files.ReadWrite.All 权限设置为应用程序,而需要委托。等待改变。 更新问题由上述更改修复
解决方案
File.readwrite.all 权限被设置为应用程序,而委托是预期的。
推荐阅读
- c++ - 如何在 C++ 中的 ArmNN for Linux 中加载 base onnx 模型
- flutter - 如何使用Provider来显示或隐藏FAB?
- php - 按两列和第二列作为日期对 SQL 进行排序
- python - 河内塔,理解代码的问题
- jenkins - Jenkins 无法发送电子邮件 - 需要身份验证
- python - 是否可以使用自定义方法创建新的 python 对象?
- powerbi - 如何在 Power BI 中获得带有动作的 GIF 图像?
- python-3.x - 数据透视表中索引的小计
- ios - 如何将算术表达式计算修复为 Int
- spring - Spring Quartz:禁用 Quartz 调度程序