简体   繁体   中英

Get folder and files Google Drive API with Shared Device and Service Account

I'm working with a Google Service Account, I have access to Google Drive API and a Shared Unit.

I need to get access to all the files and folders from a Shared Unit. I tried a lot of different ways to do this.

drive_service.files().list(
    q = f"'{parent_folder}' in parents",
    spaces = 'drive',
    supportsTeamDrives=True
).execute()

>> {'kind': 'drive#fileList', 'incompleteSearch': False, 'files': []}

drive_service.files().list(
    q = f" parents in '{parent_folder}'",
    spaces = 'drive',
    supportsTeamDrives=True
).execute()

>> {'kind': 'drive#fileList', 'incompleteSearch': False, 'files': []}
drive_service.files().list(
    spaces = 'drive',
    supportsTeamDrives=True
).execute()

>> {'kind': 'drive#fileList', 'incompleteSearch': False, 'files': []}

drive_service.drives().list().execute()

>> {'kind': 'drive#driveList',
 'drives': [{'kind': 'drive#drive',
   'id': '0AOELwkzr21lFUk9VA',
   'name': 'foo'}]}

I know a have access because I can upload files to the parent folder. Also, there are files in the parent folder.

Do you have any clue?

Thank you for your time

I figure it out.

An additional parameter had to be passed:

includeItemsFromAllDrives = True,
supportsAllDrives = True

This works:

drive_service.files().list(
    q = f"'{parent_folder}' in parents",
    spaces = 'drive',
    includeItemsFromAllDrives = True,
    supportsAllDrives = True
).execute()

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