python - makeAdmin 谷歌 API Gsuite SDK 错误
问题描述
我正在关注这篇文章以使用户成为 gsuite 的管理员: https ://developers.google.com/admin-sdk/directory/v1/reference/users/makeAdmin
我正在使用 python 这样做,我的代码是:
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'SA.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
self.delegated_credentials = credentials.with_subject('my_admin_user@domain.com')
self.service = googleapiclient.discovery.build('admin', 'directory_v1', credentials=self.delegated_credentials)
self.service.users().makeAdmin(userKey="user.email@domain.com").execute()
但不幸的是,我收到了这个错误:
> googleapiclient.errors.HttpError: <HttpError 400 when requesting
> https://www.googleapis.com/admin/directory/v1/users/user.email@domain.com/makeAdmin?
> returned "Missing required field: is_admin">
如果我尝试列出以下用户:
users = self.service.users().list(customer='my_customer').execute()
它工作正常。
is_admin
错误所指的参数是什么?我在文档中看不到任何有关它的信息。
谢谢
解决方案
Makeadmin方法也有一个 body 参数,它需要一个布尔值
{
"status": boolean
}
我认为这是您缺少的 is_admin 字段。
self.service.users().makeAdmin(userKey="user.email@domain.com", { "status": True }).execute()
推荐阅读
- python - 如何对作为单个列表且嵌套列表很少的字典值元素进行排序?
- c# - C# Bcrypt.net-next Nuget 程序集名称?
- python - 使用 python 将嵌套 XML 转换为 csv 用于任何 XML 文件
- java - EhCache 3 配置类单元测试
- c# - 程序启动时布尔值设置为真,而我没有告诉它
- android-studio - 分析应用程序窗口未显示在 Android Studio 中
- php - VichUploaderBundle,Form\Type\VichImageType 错误产生
- machine-learning - 我们可以调整测试数据上的任何参数,包括通过预处理学习的任何参数吗?
- c# - C# LINQ OrderBy() 表达式,创建嵌套泛型类型
- sql - SQL - 从历史表中返回最近的行