首页 > 解决方案 > 在将 Mircosoft graphClient 与 delta 查询一起使用时,onedrive 会抛出 Item not found 异常

问题描述

  private GraphServiceClient GetGraphClient()
    {
        var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
        {
            // get an access token for Graph
            var accessToken = GetAccessToken().Result;

            requestMessage
          .Headers
          .Authorization = new AuthenticationHeaderValue("bearer", accessToken);

            return Task.FromResult(0);
        }));

        return graphClient;
    }

私有异步任务 GetFiles(GraphServiceClient graphClient, object deltaLink) { IDriveItemDeltaCollectionPage 页面;

        if (lastDrivePage == null)
        {
          
            page = await graphClient.Drive.Root
                        .Delta()
                        .Request()
                        .GetAsync();
        }
        else
        {
            lastDrivePage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
            page = await lastDrivePage.NextPageRequest.GetAsync();
        }

        lastDrivePage = page;
        return page;
    }

当此代码要执行时,它会引发异常 Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HMD5LBBAHEK0", Request id "0HMD5LBBAHEK0:00000002":应用程序引发了未处理的异常。状态代码:未找到 Microsoft.Graph.ServiceException:代码:itemNotFound 消息:未找到项目内部错误:附加数据:日期:2021-11-12T07:06:54 请求 ID:aa304d5e-f731-4c26-af09-704627bb66a2 客户端请求-id:aa304d5e-f731-4c26-af09-704627bb66a2 ClientRequestId:aa304d5e-f731-4c26-af09-704627bb66a2

在此处输入图像描述

标签: microsoft-graph-apimicrosoft-graph-teamsmicrosoft-graph-files

解决方案


推荐阅读