accessing sharepoint sites using graph api

    IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
        .Create(clientId)
        .WithTenantId(tenantID)
        .WithClientSecret(clientSecret)
        .Build();
    
    ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );
    //To access the root SharePoint site:
    var site1 = await graphClient.Sites["root"]
               .Request()
               .GetAsync();
    //To access the Specified SharePoint site:
    var site2 = await graphClient.Sites["{site-id}"]
               .Request()
               .GetAsync();

And as @Shiva- MSFT Identity said, please add the Application permissions Sites.ReadWrite.All under the MicrosoftGraph Permissions but not under the Sharepoint Permission.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top