2

i am using pydrive that trying to query the files from the date that i created. here is my sample code:

    for f in drive.ListFile({'q':"modifiedTime > '2012-06-04T12:00:00-08:00'"}):
    for f1 in f:
        print(f1['title']+' '+f1['id'])

but while i run my code, googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v2/files?q=modifiedByMeDate+%3E+%272012-06-04T12%3A00%3A00-08%3A00%27&alt=json returned "Invalid query"> is returned.

is there something wrond in my query? thanks everyone..

chw
  • 41
  • 4
  • Is this information useful for you? https://developers.google.com/drive/api/v3/search-parameters – Tanaike Jun 28 '18 at 23:36
  • Dear, thanks for your reply and i checked that link before. and i directly copied the query of modified date "modifiedTime > '2012-06-04T12:00:00-08:00'" to my code and run, but same error is returned. – chw Jun 29 '18 at 04:09
  • I'm sorry for the inconvenience. How about modifying from ``modifiedTime`` to ``modifiedDate``. Because you are using Drive API v2. But ``modifiedTime`` is used for Drive API v3. https://developers.google.com/drive/api/v3/search-parameters If this didn't work, can you provide your script? – Tanaike Jun 29 '18 at 04:49
  • 1
    Dear, Thanks your comment and now i can run this query without error! I changed the query command from modifiedTime to modifiedDate!! :) – chw Jun 29 '18 at 08:43

1 Answers1

2

This works for me:

# Call the Drive v3 API
results = service.files().list(
    pageSize=10,
    fields="nextPageToken, files(id, name)",
    q="modifiedTime > '2012-06-04T12:00:00-08:00'"
    ).execute()
items = results.get('files', [])
if not items:
    print('No files found.')
else:
    print('Files:')
    for item in items:
        print('{0} ({1})'.format(item['name'], item['id']))

Using the GDrive Python Quickstart as reference and using v3 of Drive API.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • Dear, thanks for your comment but i am using pydrive to get the information from drive. but - i think it is a stupid question, which one is better? using pydrive or google python api? – chw Jul 04 '18 at 00:31
  • 1
    "PyDrive is a wrapper library of google-api-python-client that simplifies many common Google Drive API tasks." If the things you're doing is covered by PyDrive, no problem, I think someone just made life easier for you - just call them methods. But if you wanna do more, you ought to learn the gritty details so you won't have to wait for the developer-who-wrote-the-wrapper's updates. – ReyAnthonyRenacia Jul 04 '18 at 02:09
  • Dear, thanks for you comment and now i have a clearly concept of these stuff. i will learn more and more and it seems like a long road...:)! – chw Jul 05 '18 at 22:12