使用Microsoft Graph API获取SharePoint子站点时出现'Resource not found for the segment'错误的排查求助
我现在遇到一个棘手的问题:用C#结合Microsoft Graph API给SharePoint子站点应用保留标签时,一直触发资源找不到的错误。具体情况如下:
问题背景
我要操作的子站点名为eeps,通过浏览器直接访问https://cdkgroup.sharepoint.com/sites/slsqa/eeps完全正常,说明站点确实存在,但调用Graph API获取站点信息时就报错说找不到资源。
具体错误信息
API返回的错误内容:
"code": "BadRequest", "message": "Resource not found for the segment 'eeps'"
我的代码实现
以下是完整的代码逻辑,出错的行已经单独标记:
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder .Create(clientId) .WithClientSecret(clientSecret) .WithAuthority(new Uri($"https://login.microsoft.com/{tenantId}")) .Build(); string[] scopes = new[] { "https://graph.microsoft.com/.default" }; AuthenticationResult result = await app.AcquireTokenForClient(scopes).ExecuteAsync(); string accessToken = result.AccessToken; string documentLibraryName = "Documents"; string retentionLabelName = "Retain EUTS"; GraphServiceClient graphClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) => { requestMessage.Headers.Authorization = new AuthorizationHeaderValue("Bearer", accessToken); return Task.CompletedTask; })); // 这一行抛出错误 var site = await graphClient .Sites .GetByPath("/sites/slsqa/eeps", "https://cdkgroup.sharepoint.com") .Request() .GetAsync();
已尝试的排查动作
- 检查了Azure Entra ID中客户端ID的权限:已经配置了
Sites.Selected的应用权限 - 反复验证子站点的有效性:通过浏览器链接能正常打开目标子站点,确认站点路径和访问权限都没问题
我是不是在API调用方式、权限配置或者路径处理上漏了什么?如果需要更多细节(比如权限截图、站点结构)可以随时提供,麻烦大家帮忙看看怎么解决这个问题!
内容来源于stack exchange
相关产品推荐
相关产品推荐

