首页 > 解决方案 > “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   

标签: c#sharepointcsom

解决方案


请确保您安装了 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);  
    };

推荐阅读