C#C
C#3y ago
1 reply
Kukuba008

❔ Graph Api - load Events

Hello I'm trying to read events from calendar using Microsoft Graph Api using this code:
var scopes = new[] { "https://graph.microsoft.com/.default"};

// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "iii";

// Values from app registration
var clientId = "iii";
var clientSecret = "iii";

// using Azure.Identity;
var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
    tenantId, clientId, clientSecret, options);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);

var x = await graphClient.Users["iii"].Calendar.Events.Request().GetAsync();

*iii = normal values
The problem is that I'm getting this error:
Code: ErrorAccessDenied
Message: Access is denied. Check credentials and try again.

Even though i can read:
var x = await graphClient.Users["iii"].Calendar.Request().GetAsync();

completely fine and for both of these i need the same permission, which is: Calendars.Read.
So what am I doing wrong ?
*permissions are in the picture
Thanks
image.png
Was this page helpful?