Home > front end >  Nopermissionsinaccess token error when trying to get calendar from graph API
Nopermissionsinaccess token error when trying to get calendar from graph API

Time:07-12

there are other questions about this, but I've not seen my exact situation and I'm not sure what I am doing wrong.

My app has a client secret set up and here are the api permissions

Api examples

My code is pretty simple

    var scopes = new[] { "https://graph.microsoft.com/.default" };

            
            var tenantId = "tenenantid";

           
            var clientId = "clientid";
            var clientSecret = "secret";

           
            var options = new TokenCredentialOptions
            {
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
            };

          
            var clientSecretCredential = new ClientSecretCredential(
                tenantId, clientId, clientSecret, options);

            var graphClient = new GraphServiceClient(clientSecretCredential, scopes);


         
              var calendars = await graphClient.Users["userIdhere"].Events.Request()
              .GetAsync();
     

CodePudding user response:

I tried to reproduce the same via Postman by granting same permissions and got the error as below:

enter image description here

To resolve the error, make sure to grant Application permissions and grant admin consent as you are using client credentials grant flow:

enter image description here

After granting the Application permissions, I got the list of calendar events successfully like below:

enter image description here

Reference:

List events - Microsoft Graph v1.0 | Microsoft Docs

  • Related