MicrosoftGraph API无法将消息标记为已读 [英] MicrosoftGraph API fails to mark a message as read
问题描述
我正在使用Microsoft.Graph
nuget软件包(版本1.6.2),并且尝试将电子邮件标记为已读.
这是代码:
I am using the Microsoft.Graph
nuget package (version 1.6.2) and I try to mark an email as read.
This is the code:
msg.IsRead = true;
await MainPage.GraphServiceClient.Me.Messages[msg.Id].Request().Select("IsRead").UpdateAsync(msg);
据我了解,以上代码应仅将IsRead
属性发送到服务器以进行更新.
但是,执行此操作后,将发送整个消息对象(我已经使用Fiddler进行了验证),您会收到以下响应:
From my understanding, the above code should only send the IsRead
property to the server for update.
However, executing this, sends the whole message object (I have verified this with Fiddler) and you get this response:
{
"error": {
"code": "ErrorInvalidPropertyUpdateSentMessage",
"message": "Update operation is invalid for property of a sent message.",
"innerError": {
"request-id": "<A guid here that I wont share>",
"date": "2017-07-29T21:10:18"
}
}
}
代码正确吗,这是一个错误,我丢失了什么还是什么? 有办法解决吗?
Is the code correct, is this a bug, am I missing something or what? Is there a way around this?
推荐答案
在遇到同样的问题之后,我刚刚遇到了您的问题.
I've just encountered your question after being stuck with the same problem my self.
经过多次尝试,我发现在尝试更新(PATCH)不允许更新的字段时会出现问题.
As I came to see after several tries the problem occurs when you try to update (PATCH) fields that aren't allowed to be updated.
就您和我而言,
问题在于,我们向msg
对象发送了他的所有字段,而不仅是修补和修改的字段.
In your case and in my case as well,
The problem was that we sent the msg
object with all of his fields and not only with the patched and modified fields.
代替执行以下操作:
var msg = await MainPage.GraphServiceClient.Me.Messages[imapMessage.MessageId].Request().GetAsync();
msg.IsRead = true;
await MainPage.GraphServiceClient.Me.Messages[msg.Id].Request().Select("IsRead").UpdateAsync(msg);
首先应该只获得IsRead属性,
You should only get the IsRead property in the first place,
更新 从GraphAPI 1.9版本开始,我们只需要发送已更新的属性而没有只读属性.
Update since version 1.9 of the GraphAPI, we need to send only the updated properties without the readonly properties.
await MainPage.GraphServiceClient.Me.Messages[msg.Id].Request().Select("IsRead").UpdateAsync(new Message {IsRead = true});
希望它仍能以任何方式释放您.
Hoping it will help you if it's still releavent any way.
这篇关于MicrosoftGraph API无法将消息标记为已读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!