I am trying to get the list items from SharePoint. While executing the following code, I am getting "the remote server returned an error (403) forbidden".
try
{
using (var context = new ClientContext(siteurl + "/_api/lists/GetByTitle('" + documentlibrary + "')/items?$orderby=Id%20desc"))
{
context.Credentials = new SharePointOnlineCredentials("[email protected]", GetPasswordOfYourSite("password"));
Web web = context.Web;
context.Load(web.Lists,
lists => lists.Include(list => list.Title,
list => list.Id));
context.ExecuteQuery();
Console.ForegroundColor = ConsoleColor.White;
foreach (List list in web.Lists)
{
Console.WriteLine("List title is: " + list.Title);
}
Console.WriteLine("");
}
}
catch (Exception ex)
{
Console.WriteLine("Error is: " + ex.Message);
}
while trying to connect, getting this "the remote server returned an error (403) forbidden" exception.
Could you please what are the reasons for this issue? and how to resolve this?
thanks