简体   繁体   中英

List all files in folder in shared Google Team Drive using PyDrive

I'm trying to use PyDrive to get a list of all file ids in a Google Drive Folder. My query works when I use it on a folder within my drive but doesn't work when I try to use it on a folder in a shared Google Team Drive.

file_list = drive.ListFile({'q': "'folder_id_goes_here' in parents"}).GetList()

I tried appending arguments like 'team_drive_id' = team_drive_id_goes_here and 'supports_team_drive' = True, but I'm not sure if I'm adding these on correctly.

team_drive_id = 'team_drive_id_goes_here'

file_list = drive.ListFile({
     'q': "'folder_id_goes_here' in parents",
     'supportsTeamDrives': True,
     'teamDriveId' = team_drive_id
}).GetList()

When I add these arguments to the ListFile function, I end up getting a 'googleapiclient.errors.HttpError: <HttpError 403' error.

Does anyone know how to modify this query to work with folders in shared team drives?

I would like to propose the following modification.

From:

team_drive_id = 'team_drive_id_goes_here'
file_list = drive.ListFile({
     'q': "'folder_id_goes_here' in parents",
     'supportsTeamDrives': True,
     'teamDriveId' = team_drive_id
}).GetList()

To:

team_drive_id = 'team_drive_id_goes_here'
file_list = drive.ListFile({
    'q': "'folder_id_goes_here' in parents",
    'supportsAllDrives': True,  # Modified
    'driveId': team_drive_id,  # Modified
    'includeItemsFromAllDrives': True,  # Added
    'corpora': 'drive'  # Added
}).GetList()

or

file_list = drive.ListFile({
    'q': "'folder_id_goes_here' in parents",
    'supportsAllDrives': True,  # Modified
    'includeItemsFromAllDrives': True,  # Added
}).GetList()

Note:

  • The official document says Warning: This item is deprecated. for includeTeamDriveItems and teamDriveId . So in this case, please use includeItemsFromAllDrives and driveId , respectively.

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM