c# - 尝试从共享点获取工作簿时出现 Microsoft Graph ItemNotFound 错误
问题描述
当我使用图形资源管理器并执行 GET 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。如果我只是添加该部分,它可以找到驱动器,因此我的设置似乎没有问题。有没有人遇到过这个问题或知道如何解决这个问题?
解决方案
使用应用程序权限调用GET /drives/{drive_id}/items/{item_id}时,您的应用程序需要此处列出的应用程序权限之一,很可能是Files.Read.All
我观察到,当您拥有一个不具有所需权限之一的 access_token 时,您会得到具有误导性的itemNotFound。
在您的情况下,只需将Files.Read.All应用程序权限(需要管理员同意)添加到 Azure AD 上的应用程序。
推荐阅读
- c# - 桌面应用程序中的 SQL Server Windows 身份验证 - 连接错误
- asp.net - 为什么要创建 DBContext 的私有变量并将其初始化为类的公共构造函数?
- php - 502 Bad Gateway on fresh api-platform docker-compose
- apache - 即使在 ssl 设置之后,https 也不会提供内容,但 http 可以
- typescript - 使用新定义文件添加到现有库 typescript 类型
- python - 在 Python 中初始化一个大列表:最大大小与内存限制
- angular -
和 不知道承认但 和 被认可 - go - 在 GoLang 中将 int64 的 Slice 转换为字节数组,反之亦然
- android - 解决重新启动时自动触发警报的方法
- html - 使用 html 和 javascript 将结果四舍五入到小数点后 2 位