有没有办法使用 googleapis/google-api-python-client 库通过 externalid 搜索用户?

Is there a way to search users by externalid using the googleapis/google-api-python-client library?

我正在编写一个 python 应用程序,它使用 Google Admin SDK 在用户目录中搜索用户。我需要通过外部 ID 或员工 ID 搜索用户,它似乎没有在 python 库中实现 (https://github.com/googleapis/google-api-python-client#installation), but there is support from google as it says in their official docs, see (https://developers.google.com/admin-sdk/directory/v1/guides/search-users#examples)

如果有人能帮助指出问题,我将不胜感激。

回答

可以使用查询参数 query.

通过外部 ID 搜索用户

循序渐进

  1. 勾选Python Quickstart
  2. 使用方法users.list
  3. 定义客户。您可以使用 my_customer
  4. 定义您的 query。示例:query = 'externalId:someValue'
  5. Get 匹配 list
  6. 结果的用户

代码

results = service.users().list( customer='my_customer',
                                query='externalId:someValue',
                                orderBy='email'
                                ).execute()
users = results.get('users', [])

参考资料