[英]Microsoft Graph "Access is denied. Check credentials and try again" in C#
This is my code to get emails from my email account through Microsoft Graph, but I keep getting an error regardless on credentials.这是我通过 Microsoft Graph 从我的 email 帐户获取电子邮件的代码,但无论凭据如何,我都会不断收到错误消息。
Code:代码:
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "";
var clientId = "";
var clientSecret = "";
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var inboxMessages = await graphClient
.Users["email"]
.MailFolders["inbox"]
.Messages
.Request()
.Expand("attachments")
.Top(20)
.GetAsync();
Console.WriteLine(inboxMessages);
Console.ReadLine();
Error:错误:
Permissions:权限:
In the client credential flow there won't be any user authentication, so delegated permissions doesn't work.在客户端凭证流中,不会有任何用户身份验证,因此委托权限不起作用。 Please give application permissions in the API permissions in azure ad.
请在 azure 广告中授予 API 权限中的应用程序权限。
There are two types of permissions.有两种类型的权限。 Application permissions and delegated permissions.
应用程序权限和委托权限。 Here if you have a user logging into the app then you would use a different flow and you can use these delegated permissions.
在这里,如果您有一个用户登录到应用程序,那么您将使用不同的流程,并且您可以使用这些委派的权限。 But here there is no user as it's a client credential flow.
但是这里没有用户,因为它是客户端凭证流。 So use application permissions to make the above code work.
所以使用应用程序权限使上面的代码工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.