SharePoint Online _api/contextinfo 401 错误

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

使用C#中的HTTP客户端与SharePoint交互。 GET 请求运行正常,返回 json odata。

我尝试使用 {siteurl}/_api/contextinfo 获取表单摘要值,并不断遇到 401 响应错误。 我的代码如下 -

我查看了https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/navigate-the-sharepoint-data-struct-represented-in-the-rest-service除了与该页面上显示的网址格式可能发生冲突之外(我已经尝试了两种格式) - A。发布 https://{site_url}/_api/contextinfo b.发布 https://{site_url}/_api/doclib/contextinfo

下面的 url 字符串构建为 https://xxx.onmicrosoft.com/sites/sitename/_api/context

我仍然遇到同样的错误 - 谁能建议解决方案

`    `url = @"https://" + HostSite + @"/" + SiteRoot + "/_api/contextinfo";


      requestMessage = new HttpRequestMessage
     {
         Method = HttpMethod.Post,
         Content = new StringContent("", Encoding.UTF8, "application/json"),
         RequestUri = new Uri(url),


     };
     client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");
     requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);

     response = await client.SendAsync(requestMessage);

查看了 SharePoint API 指南,它表明它应该可以工作,但仍然出现 401 错误。已在 Entra Id 中为 Graph 和 SharePoint 设置 API 权限以进行站点管理所有级别。

http sharepoint
1个回答
0
投票

遇到这个问题好几天了:问题是,要直接查询 SharePoint API,必须提供证书以及您的客户端密钥等。

但您也可以切换到 Microsoft Graph REST API,其工作原理类似,并且可以访问许多 SharePoint 功能 - 不需要证书,也根本不需要摘要值。

文档在这些方面确实缺乏。

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