Google 目录 API 按未设置的自定义字段搜索用户

Google Directory API Search users by custom field not set

根据 Google 目录 API,您可以为用户创建自定义字段,然后通过这些字段搜索用户。

https://developers.google.com/admin-sdk/directory/v1/guides/search-users

You can search for users matching certain attributes with the users.list method of the Directory API. This method accepts the query parameter which is a search query combining one or more search clauses. Each search clause is made up of three parts:

Field
User attribute that is searched. For example, givenName. Custom fields can be searched by schemaName.fieldName.
Operator
Test that is performed on the data to provide a match. For example, the : operator tests if a text attribute contains a value.
Value
The content of the attribute that is tested. For example, Jane.

搜索布尔值似乎只显示已明确设置为 true 或 false 的用户。是否可以搜索没有设置值的用户或搜索所有不为真或不为假的值?

好像变了。当我使用

在 Google APIs Explorer 上搜索时

获取 https:// www.googleapis.com/admin/directory/v1/users?customer=my_customer&projection=full&key={YOUR_API_KEY}

它 returns 大约 70 个结果但使用

GET https:// www.googleapis.com/admin/directory/v1/users?customer=my_customer&projection=full&query=userData.enabled%3Dfalse&key={YOUR_API_KEY} returns 1 个结果和

GET https:// www.googleapis.com/admin/directory/v1/users?customer=my_customer&projection=full&query=userData.enabled%3Dtrue&key={YOUR_API_KEY} returns 没有结果。

我将大约一打设置为真,其余设置为假。只有少数几个我没有明确设置为 true 或 false。

您似乎无法搜索未明确设置的值。唯一的选择是提取设置值并找出设置值和未设置值之间的差异。例如,使用 php array_udiff 或遍历所有用户并比较值。