[英]Microsoft Graph Client SDK -filter groups by name
一个相当简单的问题,但我无法将查询 Graph 的基本httpClient
方法转换为 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}')")
如果您想切换到GraphServiceClient
类的beta
版,可以这样指定:
graphServiceClient.BaseUrl = "https://graph.microsoft.com/beta";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.