Hi @Nikhil Kamble
According to the documentation:
There are two scenarios where an app can get events in another user's calendar:
- If the app has application permissions, or,
- If the app has the appropriate delegated permissions from one user, and another user has shared a calendar with that user, or, has given delegated access to that user. See details and an example.
So, if you are using auth code flow to access other users' calendar events, make sure that the logged-in user has shared the calendar with the target user, or that the target user has granted delegated access to the logged-in user.
If you are using the client credentials flow to access other users' calendar events, then you only need to have one of the Calendars.Read
or Calendars.ReadWrite
application permissions.
using Azure.Identity;
using Microsoft.Graph;
using Newtonsoft.Json;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "{tenant id of the azure ad}";
// Values from app registration
var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";
// 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);
try
{
var events = await graphClient.Users["
.Request()
.Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"")
.GetAsync();
Console.WriteLine("events:" + JsonConvert.SerializeObject(events));
}
catch (Exception ex) {
Console.WriteLine(ex);
}