C
C#2y ago
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();
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.
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();
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
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server