Hi @John Pike
Please try to upgrade your Microsoft Graph package to version 5.0 or above:
dotnet add package Microsoft.Graph --version 5.2.0
Note that the Microsoft Graph .NET SDK v5 has removed the Request()
method.
using Azure.Identity;
using Microsoft.Graph;
using Newtonsoft.Json;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "{tenant id}";
// Values from app registration
var clientId = "{client id}";
var clientSecret = "{client secret}";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://docs.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
var result = await graphServiceClient.Users["{user id}"].Calendar.Events.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string[] { "start", "end", "bodyPreview", "body", "subject", "createdDateTime", "lastModifiedDateTime", "type" };
requestConfiguration.QueryParameters.Filter = "start/dateTime ge '2023-03-20T08:00:00'";
requestConfiguration.QueryParameters.Top = 999;
});
Console.WriteLine(JsonConvert.SerializeObject(result));
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.