0

我正在使用 Drive API 检查我的 Google Apps 域。我成功地创建了一项服务,但是当我在域上有一个暂停的用户时,我试图获取我所有用户的权限 ID 失败。使用我的 get_about 函数会导致 401 Unauthorized : Invalid Credentials。有没有办法解决这个错误?我应该以某种方式创建不同类型的服务吗?现在我被迫跳过那个用户。

#Passing in a already created user service
def get_about(service):
    return service.about().get().execute()

这是我创建服务的地方:

class DriveService(object):
    """
    The main entry class to constructing the google drive api client service
    We wrap the service so it can be used as normal but with some error
    handling provided
    """

    raw_service = None
    http = None
    auth_scope = 'https://www.googleapis.com/auth/drive'

    def __init__(self, user_email):
        key_file_path = os.path.join(os.path.split(__file__)[0],
                                 SERVICE_ACCOUNT_PEM_FILE)
        with open(key_file_path, 'rb') as f:
            key = f.read()

        credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL,
                                                key,
                                                scope=self.auth_scope,
                                                prn=user_email)
        self.user_email = user_email
        self.http = credentials.authorize(httplib2.Http())
        try:
            self.raw_service = build('drive', 'v2', http=self.http,
                             requestBuilder=BackoffHttpRequest,
                             )
        except:
            import pdb
            pdb.set_trace()

    def __getattr__(self, attr):
        try:
            return object.__getattribute__(self, attr)
        except AttributeError:
            return getattr(self.raw_service, attr)
4

1 回答 1

1

不幸的是,没有办法解决这个问题。该帐户已禁用,您将无法使用 JWT 断言对其进行任何有用的操作。

到目前为止,您需要在删除/暂停用户文件之前将其所有权转移到另一个帐户。拉出所有用户的列表 > 所有用户的所有文件 > 所有文件的所有权限。从那里,您可以在本地解析所述用户名的权限 ID,以获取您所追求的数据。在我的环境中提取这些数据大约需要 40 分钟。我相信这是第 3 方驱动应用程序(CloudLock 和通用审计工具和 Flashpanel)为了获取有用数据所做的。可能不是你想要的答案。

在这种情况下,无需断言即可提取全局驱动结果的 API 将非常有用。或者,能够通过 fileID 以外的其他方式查询权限会很好。希望这在路线图上。

于 2013-08-02T23:01:51.297 回答