我正在尝试使用C#API执行Sharepoint Online搜索:
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:未经授权'尽管我提供的凭据是正确的。我在这里缺少什么?
答案 0 :(得分:3)
您正在尝试连接到SharePoint文档库(https://foobar.sharepoint.com/_layouts/15/start.aspx#/Shared%20Documents)。尝试连接“https://foobar.sharepoint.com/”。
此外,客户端上下文可能没有足够的权限来执行搜索。