【问题标题】:GraphServiceClient filter issueGraphServiceClient 过滤器问题
【发布时间】:2021-07-26 12:57:23
【问题描述】:

我按照此页面设置了 MicrosoftGraphProvider:http://www.keithmsmith.com/get-started-microsoft-graph-api-calls-net-core-3/

这工作正常,因为我能够通过以下请求获得所有用户的列表。

var user = await _graphServiceClient.Users.Request().GetAsync();

但是,我并不总是希望所有用户都返回,因此我通过电子邮件过滤了用户。

示例说明这样做

var user = await _graphServiceClient.Users[email].Request().GetAsync();

但这总是导致找不到用户,即使我从所有用户的回复中传递了一封有效的电子邮件。

所以我尝试构建一个过滤器,并这样做。

var test = await _graphServiceClient.Users["$filter=startswith(mail,'test@email.com')"].Request().GetAsync();

var test = await _graphServiceClient.Users["$filter=(startswith(mail,'test@email.com'))"].Request().GetAsync();

这两个都返回了错误:

Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: BadRequest
Message: The $filter path segment must be in the form $filter(expression), where the expression resolves to a boolean.

当我在 Postman 中直接调用 url 时,这个过滤器可以正常工作。但我正在尝试使用他们的 sdk,但它没有按预期工作。

这个过滤查询有什么问题?

【问题讨论】:

标签: c# asp.net microsoft-graph-api microsoft-graph-sdks


【解决方案1】:

$filter 应该在Filter 方法中指定。您关注的文章并未反映当前的 API。

var users = await _graphServiceClient.Users
.Request()
.Filter("startswith(mail,'test@email.com')")
.GetAsync();

查看documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 2011-08-04
    • 2010-09-20
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多