Hi @Mario Malvido
The application context can only be used to call the /users/{user_id} endpoint and not the /me endpoint.
Additionally, /root does not exist in graph SDK 5.0 and above, the root property on driveItem is a simply shorthand to .../items/root and is omitted to avoid generating paths that have alternatives for the purposes of optimising metadata/sdk size.
So if you are trying to retrieve a list of files in the root of the user's drive, then change your code snippet to the following:
using Microsoft.Graph;
using Azure.Identity;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "xxxxxxxxxxxxxxxxxx";
var clientId = "xxxxxxxxxxxxxxxxx";
var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxx";
// 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 token = await clientSecretCredential.GetTokenAsync(new TokenRequestContext(scopes));
Console.WriteLine($"Access token: {token.Token}");*/
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var rootFolders = await graphClient.Drives["{drive_id}"].Items["root"].Children.GetAsync();
Console.WriteLine(rootFolders);
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.