MicrosoftGraph API 无法将消息标记为已读 [英] MicrosoftGraph API fails to mark a message as read

查看:33
本文介绍了MicrosoftGraph API 无法将消息标记为已读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆