图 Api 阅读电子邮件的权限

Graph Api Permission to Read Email

我有以下 C# 代码。我正在尝试按照以下 link

使用图表 api 阅读 exchange 365 中的电子邮件

Reading user emails using MS Graph API C#

 IConfidentialClientApplication cca = ConfidentialClientApplicationBuilder
                  .Create("myAppId")
                  .WithTenantId("myTenantId")
                  .WithClientSecret("myClientSecret")
                  .Build();
            ClientCredentialProvider ccp = new ClientCredentialProvider(cca);
            GraphServiceClient client = new GraphServiceClient(ccp);

  var users = await client.Users.Request()
                             .GetAsync();

我执行了它并得到了以下错误:

Microsoft.Graph.ServiceException: 'Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation.

我已根据屏幕截图授予 mail.read 和 user.read 权限。

有什么建议吗?

谢谢。

如您的代码所示,您使用 client credential flow,它使用 应用程序权限

如果要使用var users = await client.Users.Request().GetAsync();列出用户,需要设置其中一个应用权限。