GoogeDrive API-如何从文件获取权限数据

问题描述 投票:0回答:1

我想获取GoogleDrive中文件的权限数据。要获取文件,我正在使用以下代码:

        credentials = service_account.Credentials.from_service_account_file(config['credentials-file'],
                                                                        scopes=config['resource-scopes'])
        self._drive_service = discovery.build(serviceName='drive',
                                              version='v3',
                                              credentials=credentials,
                                              cache_discovery=False)

        self._drives = self._drive_service.drives().list().execute()['drives']
        files_list = self._service_v3.files().list(corpora='drive',
                                                   supportsAllDrives=True,
                                                   includeItemsFromAllDrives=True,
                                                   driveId=self._drives[0]['id'],
                                                   spaces='drive',
                                                   fields='*').execute()

执行此代码后,我得到一个看起来像这样的文件列表:

files[0] = {'id': 'file_id', 'permissionIDs' : ['permissionId1', 'permissionId1', ...], ...}

但是当我尝试获取GoogleDriveApi中指定的权限数据时,出现错误:

self._service_v3.permissions().get(fileId='file_id', permissionId='permissionId1').execute()

*** googleapiclient.errors.HttpError:https://www.googleapis.com/drive/v3/files/file_id/permissions/permissionId1?alt=json返回“找不到文件:file_id。”

我在做什么错?

google-drive-api
1个回答
0
投票

我设法使用supportsAllDrives=True标志解决了问题:

permission = self._service_v2.permissions().get(fileId='file_id', permissionId='permissionId1', supportsAllDrives=True).execute()
© www.soinside.com 2019 - 2024. All rights reserved.