Google API服务帐户GET Google Group D

2024-04-26 11:17:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取有关使用google-api-python-client和服务帐户的Google组的信息。你知道吗

服务帐户
我设置了一个服务帐户,启用了域范围的委派。你知道吗

客户_机密.json文件包含:

{
  "type": "service_account",
  "project_id": "my-project-id",
  "private_key_id": "my-priv-id",
  "private_key": "my-priv-key",
  "client_email": "my-email@email.com",
  "client_id": "my-client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "my-client-cert-url"
}

我的Python代码

CLIENT_SECRETS  = os.path.join(
os.path.dirname(__file__), "client_secrets.json")

GOOGLE_APPLICATION_CREDENTIALS  = os.path.join(
    os.path.dirname(__file__), "client_secrets.json")

scope='https://www.googleapis.com/auth/apps.groups.settings'

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = CLIENT_SECRETS

credentials = service_account.Credentials.from_service_account_file(CLIENT_SECRETS)

service = build('groupssettings', 'v1')

group = service.groups()

# Retrieve the group properties
g = group.get(groupUniqueId="group-to-seach@email.com").execute()
print('\nGroup properties for group %s\n' % g['name'])
pprint.pprint(g)

导致错误

googleapiclient.errors.HttpError: <HttpError 500 when requesting https://www.googleapis.com/groups/v1/groups/my-group-to-search%40.com?alt=json returned "Backend Error">

有人能做到这一点(使用服务帐户)?我在使用GSuites管理sdkapi和googlediscoveryapi之间有点混淆了。一旦这起作用,我需要能够创建组。你知道吗


Tags: pathhttpscomclientauthidjsonos