4

I am trying to use PyDrive to programmatically list and then download files stored on a Team Drive that I can access in a browser. When I do this:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)

file_list = drive.ListFile(
    {
        'q': "'root' in parents and trashed=false",
        'corpora': "teamDrive",
        'teamDriveId': <team drive ID>,
        'includeTeamDriveItems': "true",
        'supportsTeamDrives': "true"
    }
).GetList()
for file1 in file_list:
    print('title: %s, id: %s' % (file1['title'], file1['id']))

I only get the list of files on my personal drive, not the team drive. What am I doing wrong?

Note1: I got the <team drive ID> by opening the Team Drive (the root folder) in the browser and copying everything after "https://drive.google.com/drive/folders/"

Note2: Browser pops up at drive.ListFile and gives Authentication successful.

I Z
  • 5,719
  • 19
  • 53
  • 100

2 Answers2

7

In a team drive, files can only have one parent folder and a team drive file's parent is never root.

I was able to use the drive id again instead of root to get this to work, but I also used boolean values for true instead of strings:

drive.ListFile({'q':"'<Team_Drive_Id_Or_Folder_Id>' in parents and trashed=false", 'corpora': 'teamDrive', 'teamDriveId': '<Team_Drive_Id>', 'includeTeamDriveItems': True, 'supportsTeamDrives': True}).GetList()
Cliff
  • 136
  • 8
0

Upgrade to pydrive2 which supports this natively.

jkp
  • 78,960
  • 28
  • 103
  • 104