MS Graph API Onedrive副本返回generalException

问题描述 投票:1回答:1

我已经使用Ms Graph API开发了一个webapp,用于将文件从共享点库复制到其他共享点库(全部在线)。

我这样调用Graph API副本:

POST https://graph.microsoft.com/v1.0/drives/SrcDriveID/items/*SrcDriveItem*/[email protected]=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 + "/[email protected]=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/[email protected]=replace
{ "driveId": "b!yyyyy",  "id": "uuuuuu" },  "@microsoft.graph.conflictBehavior":"replace" }

一旦设置File.ReadWrite和Files.ReadWrite.All,它就可以与Graph API Explorer一起使用。我将再次检查它们是否已应用到我的webapp中。更新Files.ReadWrite.All权限设置为application,而需要委托。等待更改。更新通过上述更改解决的问题

sharepoint microsoft-graph onedrive azure-ad-graph-api
1个回答
0
投票

File.readwrite.all权限已设置为应用程序,而需要进行委派。

© www.soinside.com 2019 - 2024. All rights reserved.