MS Graph API Onedrive副本返回generalException
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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">
该Web应用程序正在使用委派权限,并且仅使用工作帐户。为此应用程序提供的针对Graph API的资助是:
- Directory.read.all
- File.ReadWrite
- Sites.Read.All
- User.Read
- File.ReadWrite.All
问题在我的生产环境中是系统性的。尽管权限相同,但我的开发环境中没有它。触发Web应用程序的用户(以及相关的承载密钥)对源和目标共享点库具有读/写访问权限。在目的地,他们是成员,而不是所有者。
欢迎任何帮助!
提前感谢
UPDATE:添加.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();
UPDATE我意识到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">
UPDATE:我在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一起使用。我将再次检查它们是否已应用到我的webapp中。更新Files.ReadWrite.All权限设置为application,而需要委托。等待更改。更新通过上述更改解决的问题
File.readwrite.all权限已设置为应用程序,而需要进行委派。
以上是关于MS Graph API Onedrive副本返回generalException的主要内容,如果未能解决你的问题,请参考以下文章
使用 microsoft graph api 检出 onedrive 文件的状态
Office365 Graph API 抓取OneDrive/Sharepoint文件信息
使用Graph API 操作OneDrive 文件 权限 共享