How to Specify Conditions in ListFile with Pydrive

Asked 2 years ago, Updated 2 years ago, 103 views

I would like to list only the files that I use in Python and that I am the owner (creator) of in ListFile().

drive.ListFile({'q':'title="file1"'}.GetList()

I was able to search by title or ID in , but I don't know how to specify conditions in owner's displayName or emailAddress.

GoogleDriveFile({'kind':'drive#file','id':'89h43gqhoge','title':'file1,
'owners': [{'kind': 'drive#user', 'displayName': 'tarou', 'emailAddress': '[email protected]'}],

I would like to know how to search by emailAddress in owners instead of this id or title.Thank you for your cooperation.

python google-drive-sdk pydrive

2022-09-30 20:21

1 Answers

PyDrive appears to be using Drive API v2, so be aware of this.With this in mind, I would like to reply below.

Q1: I want to list only files that I own (author) in ListFile()

Answer: If you want to retrieve only your own files as a list, you can use 'me'inowners as the value of q.Also, for non-self users, use '###email address###'in owners.Unfortunately, I can't search displayName

Q2: GoogleDriveFile({'kind':'drive#file','id':'89h43gqhoge','title':'file1,'owners':[{'kind':'drive#user','displayName':'tarou','emailAddress':'[email protected]' },instead of configuration in this email,

Answer: Drive API v2 returns all metadata if fields is not specified.If you only want to get the metadata you need as described above, you must use fields.In the above case, use items(id, title,kind,owners(displayName,emailAddress,kind)) as the fields.

If you reflect the above in your script, you will see the following:

Changed Script

drive.ListFile({'q':'me'in owners','fields':'items(id, title,kind,owners(displayName,emailAddress,kind))'}.GetList()

References:


2022-09-30 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.