问题描述
我有以下代码使用clientID和ClientSecret连接到SharePoint:-
string siteUrl = "https://****l.sharepoint.com/sites/DocumentApprovalProcess/";
string clientId = "***";
string clientSecret = "**";
using (var context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl,clientId,clientSecret))
但我收到此错误:-
'AuthenticationManager' does not contain a constructor that takes 0 arguments
解决方法
请确保您已安装Office Dev PnP:https://www.nuget.org/packages/SharePointPnPCoreOnline
using OfficeDevPnP.Core;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
string siteUrl = "https://tenant.sharepoint.com/sites/demo";
using (var cc = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl,"[Your Client ID]","[Your Client Secret]"))
{
cc.Load(cc.Web,p => p.Title);
cc.ExecuteQuery();
Console.WriteLine(cc.Web.Title);
};