【问题标题】:How do I update the user email addresses once I made a change in the Google Directory API?在 Google Directory API 中进行更改后,如何更新用户电子邮件地址?
【发布时间】:2019-11-07 20:29:04
【问题描述】:

我正在尝试使用 Google Directory API 更改组织的 Google 管理员目录中出现的所有用户的电子邮件地址。但是,我正在努力在进行更改后将更新提交到数据库。

我已设法打印出所有用户,并更改了他们的电子邮件地址,然后再次打印并查看更改是否有效。但是,这仅在本地完成,而我正在尝试将更新应用于实际的用户帐户。那么,一旦我更改了电子邮件地址,我该如何使用 API 进行实际更新?发布的代码来自 Google Python 快速入门,稍作改动

# Call the Admin SDK Directory API
print('Getting the first 10 users in the domain')
results = service.users().list(customer='my_customer', maxResults=10,
                            orderBy='email').execute()
users = results.get('users', [])
user['email']['secondaryEmail'] = user['email']['customSchema']
#HOW DO I APPLY THIS CHANGE ON THE ACTUAL USER PROFILES NOW?

if not users:
    print('No users in the domain.')
else:
    print('Users:')
    for user in users:
        print(u'{0} ({1})'.format(user['primaryEmail'],
            user['name']['fullName']))

【问题讨论】:

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


    【解决方案1】:

    您使用directory.users.update method here 重命名用户。在python中它看起来像这样:

    response = results = service.users().update(
        userKey='existing_email_address',
        body={
            'primaryEmail': 'newEmailAddress@domain.com'
        }
    ).execute()
    print(response)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-09
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 2023-02-23
      • 1970-01-01
      相关资源
      最近更新 更多