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
- Don't introduce your own spaces surrounding
=
signs,
- PyDrive uses the Google Drive API v2, so make sure you use the v2 search parameter page instead,
- 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']))