【问题标题】:ErrorAccessDenied in Microsoft Graph API while updating IsRead property of mail item更新邮件项的 IsRead 属性时 Microsoft Graph API 中的 ErrorAccessDenied
【发布时间】:2018-07-03 12:33:38
【问题描述】:

我们正在使用 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 权限。

请提出建议。

【问题讨论】:

    标签: c# office365 microsoft-graph-api office365api


    【解决方案1】:

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

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

    【讨论】:

    • 嗨,马克,感谢您的回答。但是在客户端使用 Office 365 企业帐户时,该项目仍然没有标记为已读但是对于 Office 365 商业基本帐户,它工作正常。
    猜你喜欢
    • 2023-03-03
    • 2021-01-01
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多