我正在尝试通过graph.microsoft阅读邮件,但我在底部收到错误。如果我使用SMTP并使用Pop,那么工作,但挑战是我无法在处理后删除邮件,但我可以使用Office 365 API。我该如何解决?
我的代码
var store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certs = store
.Certificates
.Find(X509FindType.FindByIssuerName, "VaultWear lcbs Cert", false);
var clientCertificate = new ClientAssertionCertificate("My Client_id", certs[0]);
authContext = new AuthenticationContext("https://login.microsoftonline.com/{my Tennant_id}/oauth2/v1.0/token");
var result = authContext.AcquireTokenAsync("My Client_id ", clientCertificate).Result;//
string tokenKey = result.AccessToken.ToString();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + tokenKey);
HttpResponseMessage response = await client.GetAsync("https://graph.microsoft.com/v2.0/me/mailfolders/inbox/messages");
string retResp = await response.Content.ReadAsStringAsync();
}
错误
{"错误":{ "代码":" InvalidAuthenticationToken", " message":"访问令牌验证失败。", " innerError":{ " request-id":" 6337285e-1503-4af8-9724-1eeecb9973a4", " date":" 2018-03-18T23:25:38" }}