连接到Sharepoint Online返回401:Unauthorized

本文关键字:Unauthorized 返回 Online Sharepoint 连接 | 更新日期: 2023-09-27 18:03:07

我正在尝试使用c# API执行Sharepoint在线搜索:

var clientContext =
    new ClientContext("https://foobar.sharepoint.com/_layouts/15/start.aspx#/Shared%20Documents");
var pw = "apassword";
var secure = new SecureString();
foreach (var c in pw) secure.AppendChar(c);
var credentials = new SharePointOnlineCredentials("adress@mail.com", secure);
clientContext.Credentials = credentials;
var keywordQuery = new KeywordQuery(clientContext);
keywordQuery.QueryText = "SharePoint";
var searchExecutor = new SearchExecutor(clientContext);
var results = searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();

我得到响应'401:未经授权',尽管我提供的凭据是正确的。我遗漏了什么?

连接到Sharepoint Online返回401:Unauthorized

您正在尝试连接到SharePoint文档库(https://foobar.sharepoint.com/_layouts/15/start.aspx#/Shared%20Documents)。尝试连接到"https://foobar.sharepoint.com/".

客户端上下文也可能没有足够的权限来执行搜索