microsoft-graph-api - Microsoft Graph 客户端 SDK - 按名称过滤组
问题描述
一个相当简单的问题,但我无法将httpClient
查询 Graph 的基本方法转换为 SDK 方法。我正在使用以下,它工作正常:
var filter = "IT";
var response = await httpClient.GetAsync($"{webOptions.GraphApiUrl}/beta/groups?$filter=startswith(displayName, '{filter}')&$select=id,displayName");
...现在我正在尝试使用 SDK 进行过滤,如下所示:
var groups = await graphServiceClient.Groups
.Request()
.Filter($"displayName startswith {filter}")
.Select("id, displayName")
.GetAsync();
我也尝试过.Filter($"startswith("displayName", {filter}))
其他变体。
我收到一个invalid filter clause
错误。有任何想法吗?
解决方案
显然它发生是因为为Filter
方法提供的过滤器表达式无效,它可以像这样验证:
var message = graphServiceClient.Groups
.Request()
.Filter($"displayName startswith '{filter}'")
.Select("id, displayName").GetHttpRequestMessage();
生成的message.RequestUri
将返回以下值:
https://graph.microsoft.com/v1.0/groups?$filter=displayName startswith '{filter}'&$select=id, displayName}
需要像这样指定有效的过滤器表达式:
.Filter($"startswith(displayName, '{filter}')")
如果您想切换到类的beta
版本GraphServiceClient
,可以这样指定:
graphServiceClient.BaseUrl = "https://graph.microsoft.com/beta";
推荐阅读
- rabbitmq - 将消息从 RabbitMQ 分发给在 Heroku dynos 上运行的消费者作为“循环”
- python - 将当前登录的用户分配为模型字段的默认值
- php - 用随机值填充数组,然后计算它们
- java - 调试动态代理创建会改变调用处理程序状态
- c++ - 在模板参数包上使用类型特征?
- android - Kotlin - Firebase - 将 Uri 保存到用户的文件夹图像不断保存错误的 Uri
- javascript - 如何使用 babel legacy 装饰器
- qt - 将一组 QML 小部件居中而不更改它们的相对对齐方式
- javascript - 查看字符串的结尾是否匹配
- concurrency - 了解希尔泽理发店问题的解决方案