这个错误信息表示在API调用目录.members.insert中,没有找到指定的groupKey资源。可能是groupKey值错误或者指定的组不存在。
以下是一个可能的解决方法的代码示例:
from googleapiclient.discovery import build
from google.oauth2.service_account import Credentials
# 通过Service Account密钥文件进行身份验证
credentials = Credentials.from_service_account_file('service_account.json')
# 构建Directory API客户端
service = build('admin', 'directory_v1', credentials=credentials)
# 设置要添加成员的组的groupKey
group_key = 'group@example.com'
# 设置要添加的成员的电子邮件地址
member_email = 'member@example.com'
try:
# 调用API添加成员
response = service.members().insert(groupKey=group_key, body={'email': member_email}).execute()
print('成员添加成功!')
except Exception as e:
print(f'API调用目录.members.insert失败,错误为:{e}')
请确保将service_account.json
替换为您自己的Service Account密钥文件,并将group@example.com
和member@example.com
替换为实际的组和成员电子邮件地址。
另外,请确保您具有适当的权限来执行此操作,以及正确的API访问范围已经设置。