1

我已经为使用 Google Directory API 的用户编写/自动化了整个终止过程(即更改密码、移动到另一个 OU 等)。这一切都很好,但是,我注意到当我使用“删除特定应用程序”时密码“调用实际上没有 ASP 被删除。当我检查管理面板时,它们都仍然存在于用户帐户中。

我在脚本中执行了大约十几个其他 Google API 调用(有效),所以,不,这不是权限/范围问题。在脚本的 ASP 部分期间不会引发任何错误。它只是“处理”呼叫并继续。很奇怪。

当我在 Google 上使用 Try this API 部分时,它工作得很好,并删除了我指定的 ASP。

还有其他人遇到这个问题吗?

这是相关代码的部分:

scopes = ['https://www.googleapis.com/auth/admin.directory.user.security',
            'https://www.googleapis.com/auth/admin.directory.user',
            'https://www.googleapis.com/auth/gmail.settings.sharing',
            'https://www.googleapis.com/auth/gmail.modify',
            'https://www.googleapis.com/auth/admin.datatransfer',
            'https://www.googleapis.com/auth/admin.directory.group']

credentials = ServiceAccountCredentials.from_json_keyfile_name('../service-account-key.json', scopes=scopes)

delegated_credentials = credentials.create_delegated('REDACTED')
http_auth = delegated_credentials.authorize(Http())

directory_service = discovery.build('admin', 'directory_v1', http=http_auth)

def remove_asps():
    ##############################################################################################################################
    '''
    REMOVE ALL APP SPECIFIC PASSWORDS
    '''
    ##############################################################################################################################
    asp = directory_service.asps().list(userKey='{0}'.format(user_email)).execute()
    app_specific_passwords = asp.get('items', [])

    print('3) Removing App Specific Passwords:')
    if not app_specific_passwords:
        print('- {0} does not have any App Specific Passwords to remove.'.format(user_email))
        print('')
    else:
        for app_specific_password in app_specific_passwords:
            print('- Removing App Specific Password - {0} from {1}'.format(app_specific_password['name'],user_email))
            delete_asps = directory_service.asps().delete(userKey='{0}'.format(user_email),codeId='{0}'.format(app_specific_password['codeId']))
            print('Done.')
            print('')

我还尝试将值硬编码到调用中并删除 for 循环,而不是使用变量,这也不起作用。

日志显示调用已运行,但未引发错误:

googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/0?
googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/1?
googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/2?

在此先感谢您的帮助!

4

0 回答 0