'AuthenticationManager'不包含带有0个参数的构造函数

问题描述

我有以下代码使用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

您可以参考这篇文章:https://www.c-sharpcorner.com/article/connect-to-sharepoint-online-site-with-app-only-authentication/

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);  
    };