我正尝试通过我的 B2C AAD 租户通过 Microsoft Graph API 获取用户总数,但响应似乎出错或省略了 @odata.count
属性。
在线反馈也很复杂,有些人说 $count
仍然不受支持,即使官方文档说/users 支持 $count
。
https://learn.microsoft.com/en-us/graph/query-parameters#count-parameter
我试过通过graph api在线版: https://developer.microsoft.com/en-us/graph/graph-explorer?request=users?$count=true&method=GET&version=v1.0
结果是:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"@odata.count": 31,
"value": [
...
]
}
但是通过 postman 之类的东西做同样的事情让我得到了这个结果:
GET /v1.0/users?$count=true HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer [token]
ConsistencyLevel: eventual
{
"error": {
"code": "Request_BadRequest",
"message": "This request is not supported by the service",
"innerError": {
"date": "2020-10-09T18:19:44",
"request-id": "4d97fd77-19ad-42f9-9357-66c24c867ce2",
"client-request-id": "4d97fd77-19ad-42f9-9357-66c24c867ce2"
}
}
}
如果我删除 ConsistencyLevel
header ,我会得到一个有效响应,但没有 @odata.count
属性。
我是否缺少某些 Graph Api 权限,或者这是预期的?
最佳答案
对于 B2C 租户,此/users 端点尚不支持用户计数。但对于一般的 Azure AD 租户,当您按照以下这些步骤操作时,它将为您提供计数。
- 选择测试端点。 (
https://graph.microsoft.com/beta/users?$count=true
) - 在 QueryString 中添加 $count=true。
- 将
ConsistencyLevel = eventual
添加到请求 header 。
您将看到如下结果。
你也可以引用这个Document .
请在 Microsoft Graph Feedback Forum 中提出功能请求以便产品团队将来可以将此功能添加到 b2c 租户。
关于azure-active-directory - 用户的 Microsoft Graph Api $count 响应不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64285552/