Ошибка : запрос me действителен только с потоком делегированной проверки подлинности.
Я использую библиотеку Microsoft Graph версии 5.61.0.
Код:
Код: Выделить всё
private static async Task 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}");
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... tication-f
Мобильная версия