I am trying to access another site collection with client Id and secret, I want to retrieve a list on another website, currently I tried using this method
string siteUrl = "https://xyz.sharepoint.com/sites/MyList/";
string clientId = "<client-id>";
string clientSecret = "<client-secret>";
using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl,clientId,clientSecret))
{
Web oWebsite = clientContext.Web;
List lList = oWebsite.Lists.GetByTitle("List");
clientContext.Load(list);
clientContext.ExecuteQuery();
}
It returned an exception of access denied, but I already added app permission to https://xyz.sharepoint.com/sites/MyList/
using _layouts/15/appinv.aspx
URL