I have an Azure function (Timer) on .NET 8.0 Isolated that gets files in a one drive folder, but I get this error:
Error: me request is only valid with delegated authentication flow.
I'm using the Microsoft Graph library version 5.61.0.
Code:
private static async Task<GraphServiceClient> GetAuthenticatedGraphClient()
{
var tenantId = Environment.GetEnvironmentVariable("TenantId");
var clientId = Environment.GetEnvironmentVariable("ClientId");
var clientSecret = Environment.GetEnvironmentVariable("ClientSecret");
var scopes = new[] { "https://graph.microsoft.com/.default" };
var options = new ClientSecretCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
return graphClient;
}
public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer)
{
_logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
var txtSourceFolder = Environment.GetEnvironmentVariable("txtSourceFolder");
var graphClient = await GetAuthenticatedGraphClient();
var driveID = await graphClient.Me.Drive.GetAsync();
var driveItem = graphClient.Drives[driveID.Id]
.Items["root"]
.ItemWithPath(txtSourceFolder)
.Content
.GetAsync();
if (myTimer.ScheduleStatus is not null)
{
_logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");
}
}
How can I able to get all files in a one drive folder?



.Users["user_id"]instead of.Me