Odata $ filter用于Office 365 REST API中的日期 [英] Odata $filter for the date in the Office 365 REST API

查看:255
本文介绍了Odata $ filter用于Office 365 REST API中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用REST API从用户的Office 365帐户中检索用户的事件,但已通过开始"字段进行了过滤.例如,检索在日期之后发生的所有事件:2014-08-29T09:13:28',但我总是在检索此错误消息

I'm trying to retrieve events for a user from its Office 365 account using the REST API but filtered by the field "Start". For instance, retrieve all the events that will happen after the date: 2014-08-29T09:13:28' but i'm always retrieving this error message

{
  "error": {
    "code": "ErrorInvalidUrlQuery",
    "message": "The query parameter '$filter' is invalid.",
    "innererror": {
      "message": "The query parameter '$filter' is invalid.",
      "type": "Microsoft.Exchange.Services.OData.InvalidUrlQueryException",
      "stacktrace": " at Microsoft.Exchange.Services.OData.Web.ODataQueryOptions.Populate()
 at Microsoft.Exchange.Services.OData.ODataContext..ctor(HttpContext httpContext, Uri requestUri, ServiceModel serviceModel, ODataPathWrapper odataPath, ODataUriParser odataUriParser)
 at Microsoft.Exchange.Services.OData.Web.RequestBroker.InitializeODataContext()
 at Microsoft.Exchange.Services.OData.Web.RequestBroker.Process()",
      "internalexception": {
        "message": "A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.Int32' for operator kind 'Equal'.",
        "type": "Microsoft.OData.Core.ODataException",
        "stacktrace": " at Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right)
 at Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
 at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)
 at Microsoft.OData.Core.UriParser.Parsers.FilterBinder.BindFilter(QueryToken filter)
 at Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmNavigationSource navigationSource)
 at Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilter()
 at Microsoft.Exchange.Services.OData.Web.ODataQueryOptions.Populate()"
      }
    }
  }
}

这是我尝试过的所有事情:

Here all the thing i've tried:

[ressource] = https://outlook.office365.com/

[ressource]=https://outlook.office365.com/

url:[ressource] EWS/OData/Me/Events?$ filter = Start%20eq%20DateTime'2012-05-29T09:13:28'

url: [ressource]EWS/OData/Me/Events?$filter=Start%20eq%20DateTime'2012-05-29T09:13:28'

URL:[ressource] EWS/OData/Me/Events?$ filter = Start%20eq%20DateTime'20141231'

url: [ressource]EWS/OData/Me/Events?$filter=Start%20eq%20DateTime'20141231'

URL:[ressource] EWS/OData/Me/Events?$ filter = month(Start)%20eq%2012

url: [ressource]EWS/OData/Me/Events?$filter=month(Start)%20eq%2012

我尝试在字符串字段上使用$ filter或在 Start 字段上使用$ select,它运行良好,所以我认为我的错误是由日期格式引起的,但我不知道如何解决它,所以如果有人可以帮助我,那真是太好了!

And i've tried the $filter on string field or the $select on the field Start and it worked perfectly so i think my error is caused by the date format but i don't know how to solve it, so if anybody could help me on that, it woud be great!

谢谢!

推荐答案

按日期过滤确实可以,但是OData v4规范中不能做所有事情.例如,这些都对我有用:

Filtering on dates does work, but you can't do everything in the OData v4 spec. For example, these all work for me:

/Me/Events?$filter=Start eq 2014-08-28T21:00:00Z
/Me/Events?$filter=Start ge 2014-08-28T21:00:00Z

在其前面添加"DateTime"会使它失败.与月份功能相同.如果您坚持使用上面的格式,那么它应该对您有用.

Adding the "DateTime" in front of it makes it fail. The same with the month function. If you stick with the format above it should work for you.

这篇关于Odata $ filter用于Office 365 REST API中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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