【问题标题】:How can I access Google Directory API using service account json如何使用服务帐户 json 访问 Google Directory API
【发布时间】:2021-06-12 05:29:44
【问题描述】:

我有一个服务帐户密钥 json 文件,如下所示:

{
  "type": "service_account",
  "project_id": "project-id",
  "private_key_id": "key-id",
  "private_key": "-----BEGIN PRIVATE KEY-----\nprivate-key\n-----END PRIVATE KEY-----\n",
  "client_email": "service-account-email",
  "client_id": "client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-account-email"
}

如何访问 Google Directory API: https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list

使用 python 使用服务帐户密钥 json 文件。

【问题讨论】:

    标签: python google-api google-oauth google-directory-api


    【解决方案1】:

    要使用服务帐户访问目录 API,您必须使用域范围的委派。详情请见Perform Google Workspace Domain-Wide Delegation of Authority

    【讨论】:

    • 只使用了ServiceAccountCredentials.from_json_keyfile_name(filename) 而不是ServiceAccountCredentials.from_p12_keyfile()
    猜你喜欢
    • 2020-04-13
    • 2020-07-27
    • 2014-02-01
    • 2018-10-06
    • 2013-08-30
    • 2015-12-17
    • 2018-08-22
    • 2017-06-26
    • 2020-01-06
    相关资源
    最近更新 更多