我已经开始开发一些API,以在我的G Suite目录中创建用户。我遵循了服务帐户教程以及python的目录教程。我拥有的代码非常简单,只需测试一下它将如何工作即可。
from google.oauth2 import service_account
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user']
SERVICE_ACCOUNT_FILE = 'file'
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('admin', 'directory_v1', credentials=creds)
results = service.users().list(customer='i am not sure what customer is', maxResults=10, orderBy='email').execute()
#this line produces the error.
#Vscode also states the service has no member users. But I did install all #the libraries
users = results.get('users', [])
print(users)
对我来说,有关大多数事情的文档尚不清楚。当我运行这个我得到
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/admin/directory/v1/users?customer=students&maxResults=10&orderBy=email&alt=json returned "Bad Request">
当我将客户从my_customer
其他变为其他时,我得到了Invalid Input
。关于什么可能导致此错误的建议,最好是如何通过服务帐户使用此api?现在,我确实启用directory api
并创建了服务帐户,还下载了服务帐户文件。我错过了一步吗?如果有人拥有我找不到的更好的文档,我也希望这样做。
确保服务帐户已启用域范围委派并具有适当的范围。