.Net 6 環境でpnp.Frameworkを使用している場合。Sharepoint データを取得するには認証済みのクライアント コンテキストが必要ですが、 context.ExecuteQuery()の実行中に 403forbidden に直面しています。
クライアントから環境にデータを取得するために clientId および clientSecret モードの認証を使用したいのですが、403 禁止要求に直面しています。
特定の Azure Active Directory にアプリを登録し、次のアクセス許可を追加しました。
using PnP.Framework;
using System.Security;
using System.Web;
namespace SharePointOnlinePNPProject
{
public class Program
{
static async Task Main(string[] args)
{
string appID= "appId/clientId";
string tenantId = "<tenantId>";
string clientSecret = "";
string queueTestingLink = "Input sharepoint url";
Uri site = new Uri("https://clientDomain.sharepoint.com");
string filePath= "/Shared Documents/Case Studies"
SecureString password = new SecureString();
foreach (char c in passcode)
{
password.AppendChar(c);
}
var scopes = new string[] { hostLink + ".default" };
try
{
using (var context = new AuthenticationManager().GetACSAppOnlyContext(site.OriginalString, appID, clientSecret))
{
var folder = context.Web.GetFolderByServerRelativeUrl(filePath);
context.Load(folder);
context.ExecuteQuery();
Console.WriteLine(folder.Name);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}