I am using simple console application to pull data from a SharePoint Online list using the following code

string siteUrl = "https://MyServer.sharepoint.com/sites/MySiteCollection";
string userName = "[email protected]"
var passWord = new SecureString();

foreach (char c in "myPassword") passWord.AppendChar(c);

            ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new SharePointOnlineCredentials(userName, passWord);
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                "<Value Type='Number'>10</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
            ListItemCollection collListItem = oList.GetItems(camlQuery);



            foreach (ListItem oListItem in collListItem)
                Console.WriteLine("ID: {0} \nTitle: {1} \nBody: {2}", oListItem.Id, oListItem["Title"], oListItem["Body"]);

However when I run this program I receive the following error

Cannot contact web site 'https://myserver.sharepoint.com/' or the web site does not support SharePoint Online credentials

When I put the full link of the list in the browser I can access it however when I put in the default site collection url i am getting denied access due to permissions.

Is it possible to pull data from this list if i specifically only have access to the list site or do i need access in parent site?

  • Try connecting to the site collection using App Only Authentication (Instead of using username and password you have to use Client Id and Client Secret). Reference Commented Jun 22, 2020 at 13:22

1 Answer 1


In order to connect to your SharePoint Online site, you must enable legacy authentication protocols in your tenant (set LegacyAuthProtocolsEnabled to TRUE).

To enable legacy authentication protocols, run the following commands against your SharePoint Online tenant (using PowerShell):

Connect-SPOService -URL https://XXXX-admin.sharepoint.com
Set-SPOTenant -LegacyAuthProtocolsEnabled $True

where ‘XXXX‘ is your tenant name


  • Changes may take up to 24 hours to take effect.

For more details refer to below article:


  • That seems to have resolved the issue. Thank you! Commented Jun 25, 2020 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.