Office 365 Graph API - 大于接收日期的过滤器

Dav*_*der 5 odata office365api microsoft-graph-api

我正在尝试对 Office 365 Graph API 执行查询以说“在 {someISODateTimeString} 之前给我所有电子邮件”

例如:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime gt 2016-02-26T14:41:08Z
Run Code Online (Sandbox Code Playgroud)

看起来 gt(大于)实际上是大于或等于(ge),因为上面的查询返回了一封电子邮件,其中包含我传递给查询的确切 receivedDateTime 值。

所以我尝试了一个解决方法:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime ne 2016-02-26T14:41:08Z AND receivedDateTime ge 2016-02-26T14:41:08Z
Run Code Online (Sandbox Code Playgroud)

这也未能省略接收日期为 2016-02-26T14:41:08Z 的电子邮件。

任何有关如何在接收日期实现“大于”查询的帮助将不胜感激。

小智 11

您所看到的行为实际上是由于 REST API 的精度损失造成的。大多数日期字段(包括 receivedDateTime)实际上以比秒更高的精度存储。当前发生的情况是您的请求正在转换为一个查询,其中收到的日期时间 > 14:41:08.0000。出现在 14:41:08.01 的消息在技术上比这要大,即使精度被砍掉使其看起来相等。

您可以使用的解决方法(我们在内部也希望在所有“gt”或“lt”场景中应用)是在下一个单元中使用“ge”,因此在您的示例中:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime ge 2016-02-26T14:41:09Z
Run Code Online (Sandbox Code Playgroud)