1

this functions:

drive.ListFile({'q': " id = '"+Value+"' and trashed=false"}).GetList()

return: "Invalid query"

The problem lies in the selector 'id', if I raise this condition I return a dictionary with the parameter 'id'

I am used this doc, https://developers.google.com/drive/v2/reference/files/list and https://developers.google.com/drive/v3/web/search-parameters

It works perfectly for other selectors, but for 'id' should not be

simone989
  • 397
  • 1
  • 3
  • 8

2 Answers2

4

EDIT: Here is how you can access metadata, and get and set content of an existing file by its ID.

# Calling CreateFile() with an existing ID links it to the already existing file.
gdrive_file = drive.CreateFile({'id': '<your file id>'})
gdrive_file.FetchMetadata() # Only needed if you want to view or edit its metadata.
# Do things with metadata here as needed.

gdrive_file.GetContentFile('dog.png') # Download content file.

# And/or upload a new content file.
gdrive_file.SetContentFile('cat.png') 
gdrive_file.Upload()

And, of course, the docs have a bunch of examples.

Original: Have a look at the docs for file listings for examples.

Make sure that you

  1. Don't introduce your own spaces surrounding = signs,
  2. PyDrive uses the Google Drive API v2, so make sure you use the v2 search parameter page instead,
  3. The ID is the folder ID assigned by Google Drive, this SO question lists ways to find the ID.

For example:

from pydrive.drive import GoogleDrive

drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
folder_id = "insert your folder ID here"

# Auto-iterate through all files in the specified folder.
file_list = drive.ListFile({
    'q': "{id} in parents and trashed=false".format(id=folder_id)
}).GetList()

for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))
Community
  • 1
  • 1
Robin Nabel
  • 2,170
  • 1
  • 21
  • 26
1

id is not a supported query field for doing file search.

Check the documentation for Drive API v2 to see valid fields to search by.

danielx
  • 1,785
  • 1
  • 12
  • 23