如何在Microsoft Graph中按日历事件的location/displayName筛选?
解决Microsoft Graph API筛选日历事件location/displayName的问题
我之前也碰到过类似的情况,咱们一步步来排查解决:
1. 注意属性名的大小写问题
Graph API的属性名是严格区分大小写的,你写的location/displayname里的displayname要改成**displayName**(N是大写的),这是最容易踩的坑。
2. 处理空值避免报错
有些日历事件可能没设置location属性,直接对location/displayName用startsWith会触发错误。建议先判断该属性不为null,再进行筛选。
修正后的查询示例
结合上面两个点,你的查询应该调整成这样:
/me/calendarview?startdatetime=01-01-2019&enddatetime=12-31-2019&$filter=(isorganizer eq true) and (location/displayName ne null) and startsWith(location/displayName,'Conference')&$top=100&$select=subject,organizer,attendees,start,end,location&$orderby=start/dateTime
额外排查小技巧
- 如果还是有问题,可以先去掉
$filter参数,请求几个事件,确认返回的location结构里确实存在displayName字段; - 也可以先用精确匹配测试:
$filter=location/displayName eq 'Conference Room - Baker',确认能正常返回结果后,再换成startsWith。
内容的提问来源于stack exchange,提问作者Glenn
相关产品推荐
相关产品推荐

