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
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:
To resolve the error, make sure to grant Application
permissions and grant admin consent as you are using client credentials grant flow:
After granting the Application
permissions, I got the list of calendar events successfully like below:
Reference: