更新邮件项目的IsRead属性时,Microsoft Graph API中的ErrorAccessDenied

时间:2018-07-03 12:33:38

标签: c# office365 microsoft-graph office365api

我们正在使用Microsoft graph API进行日历和邮件项目处理。我们从office 365帐户中选择项目,处理该项目,然后将其标记为已读,然后删除该项目,以便不再对其进行处理。 在标记项为读取过程中,我们有以下方法

MarkReadMail()

{

var response = graphClient.Me.Messages[itemID].Request().Select("IsRead").GetAsync();

var msg = response.Result;

msg.IsRead = true;

graphClient.Me.Messages[itemID].Request().Select("IsRead").UpdateAsync(msg);

}

MarkReadMail()在Office 365商业基本帐户上可以正常使用,但在客户端使用Office 365企业帐户,则出现以下错误:

Message: Exception occured in method MarkReadMail  :Code: ErrorAccessDenied
Message: Access is denied. Check credentials and try again.
Inner error
 Stack Trace:   at Microsoft.Graph.HttpProvider.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.BaseRequest.<SendAsync>d__32`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.MessageRequest.<UpdateAsync>d__8.MoveNext()

尽管如此,我们在两个帐户的委派权限下都提供了Mail.ReadWrite权限。

请提出建议。

1 个答案:

答案 0 :(得分:2)

您无法发布从GET接收到的对象,因为该对象包含只读属性(即id)。您需要发布一个仅包含您要更新的属性的新对象:

graphClient
  .Me
  .Messages["itemID"]
  .Request()
  .UpdateAsync(new Message(){ IsRead = true });