【问题标题】:Microsoft Graph ItemNotFound error when trying to get a workbook from sharepoint尝试从共享点获取工作簿时出现 Microsoft Graph ItemNotFound 错误
【发布时间】:2021-04-13 13:00:08
【问题描述】:

我遵循了这个教程:https://mihai-albert.com/2020/05/13/using-microsoft-graph-to-modify-excel-files-stored-in-sharepoint-online-with-c/

当我使用图形浏览器并执行 获取https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='{search-text}')?select=name,id,webUrl 然后我没有问题地得到项目ID。 但是当我想在我的应用程序中获取工作簿时

 private readonly GraphServiceClient _graphServiceClient;
        public GraphService(
           IOptions<AzureAdOptions> azureAdOptions)
        {
            var confidentialClientApplication = ConfidentialClientApplicationBuilder
                   .Create(azureAdOptions.Value.ClientId)
                   .WithTenantId(azureAdOptions.Value.TenantId)
                   .WithClientSecret(azureAdOptions.Value.ClientSecret)
                   .Build();

            var authProvider = new ClientCredentialProvider(confidentialClientApplication);
            _graphServiceClient = new GraphServiceClient(authProvider);
        }

        public async Task Test()
        {
            try {
                var range = await _graphServiceClient.Drives[{drive-id}].Items[{item-id}]
                .Request()
                .GetAsync();
               

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

然后我得到一个 itemnotfound 错误,尽管输入了正确的 id。 如果我只是添加该部分,它可以找到驱动器,因此我的设置似乎没有问题。 有没有人遇到过这个问题或知道如何解决这个问题?

【问题讨论】:

    标签: c# microsoft-graph-api


    【解决方案1】:

    当使用应用程序权限调用 GET /drives/{drive_id}/items/{item_id} 时,您的应用程序需要列出的应用程序权限之一here 很可能是 Files.Read .全部

    我观察到,当您的 access_token 没有所需的权限之一时,您会得到 itemNotFound,这是具有误导性的。

    在您的情况下,只需将 Files.Read.All 应用程序权限(需要管理员同意)添加到 Azure AD 上的应用程序。

    【讨论】:

    • 非常感谢!我实际上最终想通了,但忘记更新这篇文章了。该错误确实具有误导性。
    猜你喜欢
    • 1970-01-01
    • 2017-06-10
    • 2019-11-13
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    相关资源
    最近更新 更多