c# - 使用 Microsoft Graph SDK 获取具有特定电子邮件域的所有用户
问题描述
我想使用 Microsoft Graph SDK 对 Microsoft Graph API 进行此查询。我想让所有用户在电子邮件地址中的域是@something.com。
将 $filter 与 endsWith 运算符一起使用
GET ../users?$count=true&$filter=endsWith(mail,'@something.com')
我尝试了以下代码行:
var users= await _graphServiceClient.Users.Request().Filter("mail '@something.com'").Select(u => new {
u.Mail,
u.DisplayName,
}).GetAsync();
我得到的错误是:
Microsoft.Graph.ServiceException: 'Code: BadRequest
Message: Invalid filter clause
没有过滤器,它工作正常。我错过了什么吗?
参考:高级查询:https ://docs.microsoft.com/en-us/graph/query-parameters Microsoft Graph SDK:https://docs.microsoft.com/en-us/graph/sdks/create-requests?选项卡=CS
解决方案
如果要使用$count
查询参数,则需要添加ConsistencyLevel
带有eventual
值的标头。
GET /users?$count=true&$filter=endsWith(mail,'@something.com')
ConsistencyLevel: eventual
在 C# 中为请求指定标头选项和查询选项:
var options = new List<Option>();
options.Add(new HeaderOption("ConsistencyLevel", "eventual"));
options.Add(new QueryOption("$count", "true"));
将endsWith
运算符添加到过滤器。
var users = await _graphServiceClient.Users
.Request(options)
.Filter("endsWith(mail,'@something.com')")
.GetAsync();
推荐阅读
- sqoop - 无法将数据从 Informix 非事务性数据库导入 HDFS
- c# - Apache Ignite.NET 和 AppDomain.CurrentDomain.ProcessExit
- java - DAO 层只需要一些参数来创建对象
- redhat - 使用 RPM 卸载软件包时出现意外失败的依赖项
- ios - 在更改 UITextView 的字符间距时如何避免这种情况?
- python - 在没有循环的情况下替换 Pandas 列中的多个值
- jenkins - 如何在 gitlab 中为多分支管道 jenkins 添加 webhook
- mysql - 在 Fedora 27 / 28 上启动 MariaDb / MySQL 的问题
- python - 查找 2df python 之间值的相似性
- angular - 将数组数据显示为列表