我正在尝试在 Outlook 帐户上回复电子邮件。但是当我尝试创建回复(尚未发送)时,出现以下异常:
ServiceException:代码:RequestBroker--ParseUri
消息:未找到段“microsoft.graph.createReply”的资源。
显然,问题出在 Url 但没有意义,因为当我尝试在创建回复之前获取消息时,除了我尝试为该消息创建回复时,一切正常。
这是代码:
ConfidentialClientApplication cca = new ConfidentialClientApplication(
[client_id], [redirect_uri],
new ClientCredential([secret]),
new TokenCache(), null);
string[] scopes = new string[]
{
"email",
"https://outlook.office.com/mail.read",
"https://outlook.office.com/mail.read.shared",
"https://outlook.office.com/mail.readwrite",
"https://outlook.office.com/mail.readwrite.shared",
"https://outlook.office.com/mail.send",
"https://outlook.office.com/mail.send.shared"
};
AuthenticationResult result = (cca as IByRefreshToken).AcquireTokenByRefreshTokenAsync(scopes, [refresh_token]).Result;
GraphServiceClient client = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new
AuthenticationHeaderValue("Bearer", result.AccessToken);
return Task.FromResult(0);
}));
string id = [message_id];
Message details = client
.Me
.Messages[id]
.Request()
.GetAsync()
.Result; // JUST FOR TESTING, THIS WORKS!
Message reply = client
.Me
.Messages[id]
.CreateReply()
.Request()
.PostAsync().Result; // THIS FAILS!!!
reply.Body.ContentType = BodyType.Html;
reply.Body.Content = [html_code];
client
.Me
.Messages[reply.Id]
.Request()
.UpdateAsync(reply); // HOPE THIS WORKS
client
.Me
.Messages[reply.Id]
.Send()
.Request()
.PostAsync()
.Wait(); // HOPE THIS WORKS TOO
我正在使用 .NET 4.7.2、Microsoft.Graph 1.17 和 Microsoft.Identity.Client v3.0.2-preview(这是因为如果我尝试使用任何稳定的版本,我在尝试仅使用刷新令牌)