【问题标题】:Can't create aliases when using google directory API使用 google 目录 API 时无法创建别名
【发布时间】:2019-03-29 02:53:54
【问题描述】:

我的代码如下所示。我的问题是,当我尝试更新“别名”字段时,它不会发生。我的实现有什么问题?

store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))

body = { "name":{"familyName": "Aaab", "givenName": "Aaab"}, "password": "test@test", "primaryEmail": "testAAb@aaaa.no", "secondaryEmail": "test@gmail.com", 'aliases': ['testLeader@test.com']}
user_add = service.users().insert(body=body).execute()

使用其字段创建的用户:

    {'kind': 'admin#directory#user', 'id': '106377021897584806221', 'etag': '"TN30oD80QTVK45AAxvl_wbzs4vs/4WNsaqcVI4y7ARsciDEXH7K8Hh4"', 'primaryEmail': 'testaab@test.no', 'name': {'givenName': 'Aaab', 'familyName': 'Aaab', 'fullName': 'Aaab Aaab'}, 'isAdmin': False, 'isDelegatedAdmin': False, 'lastLoginTime': '1970-01-01T00:00:00.000Z', 'creationTime': '2018-10-24T16:43:27.000Z', 'agreedToTerms': True, 'suspended': False, 'archived': False, 'changePasswordAtNextLogin': False, 'ipWhitelisted': False, 'emails': [{'address': 'testaab@test.no', 'primary': True}], 'customerId': 'C02dcimb3', 'orgUnitPath': '/', 'isMailboxSetup': True, 'isEnrolledIn2Sv': False, 'isEnforcedIn2Sv': False, 'includeInGlobalAddressList': True}

【问题讨论】:

  • “不会发生”是什么意思?我所看到的只是你创建了一个带有 aliases 键值对的字典?
  • 创建的用户不会得到别名字段
  • 查看documentation 我不认为aliases 是创建用户时的有效字段。
  • 啊哈,所以你必须手动完成......

标签: python api google-api google-workspace google-directory-api


【解决方案1】:

问题似乎是您在 Google Directory API 中创建用户时无法为其指定别名。正如文档中列出的 here 一样,aliases 没有字段。

要为用户添加别名,似乎需要使用不同的 API 调用。您必须使用alias.insert API 调用手动插入所需的每个别名,如here 所列。您似乎只需要唯一的 userKey 作为要传递的字段以及用户的别名。

此 API 调用的确切 Python 文档已列出 here

使用此函数的示例代码:

body = {"alias": "testLeader@test.com"}
service.users().aliases().insert(userKey=key, body=body).execute()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-06
    • 2015-12-18
    • 2016-05-03
    • 2022-06-17
    • 2018-02-06
    • 1970-01-01
    相关资源
    最近更新 更多