Bijan
Bijan

Reputation: 8586

Google Drive API Cannot See Files in Shared Folder

I have created a Service Account and made this account ([email protected]) be a Manager in a Shared Drive.

I am able to retrieve the shared folder ID by running service.drives().list(pageSize=10).execute()

But if I run:

folder_id = '0ACNaJE1nx6YwXXXXXXX' # Same folder ID as above
query = "'%s' in parents" % folder_id
response = service.files().list(q=query, spaces='drive', fields='files(id, name, parents)').execute()

It returns {'files': []} even though the shared folder contains some files. What am I doing wrong?

Upvotes: 1

Views: 1381

Answers (1)

Tanaike
Tanaike

Reputation: 201378

I believe your goal and your current situation as follows.

  • You want to retrieve the file list from the specific folder in the shared Drive using googleapis for python.
  • Your service in your script has the permission for retrieving the file list from the shared drive.

In this case, how about including includeItemsFromAllDrives=True, supportsAllDrives=True and corpora="allDrives" in the query parameter of the method of files.list in Drive API? When your script is modified, it becomes as follows.

Modified script:

folder_id = '0ACNaJE1nx6YwXXXXXXX' # Same folder ID as above
query = "'%s' in parents" % folder_id
response = service.files().list(q=query, pageSize=1000, includeItemsFromAllDrives=True, supportsAllDrives=True, corpora="allDrives", fields='files(id, name, parents)').execute()

Note:

  • In this modified script, it supposes that you have the permission for retrieving the file metadata from the shared drive. Please be careful this.

Reference:

Upvotes: 7

Related Questions