【问题标题】:Google Directory API Python ETL谷歌目录 API Python ETL
【发布时间】:2022-01-04 06:04:51
【问题描述】:

我正在尝试为 Google Workspace 构建目录同步 ETL,但我从代码 sn-p 中得到 403。

from google.oauth2 import service_account
from googleapiclient.discovery import build

SCOPES = ['https://www.googleapis.com/auth/admin.directory.user.readonly']
SERVICE_ACCOUNT_FILE = './credentials.json' #TODO: these creds need to be passed in more safely.

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

service = build('admin', 'directory_v1', credentials=credentials)

results = service.users().list(domain='mydomain.com').execute()
users = results.get('users', [])

服务帐户已被授予所列范围的域范围委派,并且应该能够访问 API。其他类似的帖子提到域管理员必须批准请求,但在我需要每周运行多次而没有任何管理员干预的情况下,这没有任何意义。

【问题讨论】:

    标签: python google-admin-sdk


    【解决方案1】:

    使用用户 API 需要 用户管理管理员 角色(或等效的自定义角色)。你可以grant this role to a service account,那么你根本不需要域范围的委派。

    【讨论】:

      猜你喜欢
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 2016-08-01
      • 1970-01-01
      • 2014-12-02
      • 2022-06-15
      相关资源
      最近更新 更多