Google Drive REST API - why doesn't "modifiedDate" query field return any results when listing children?

415 views Asked by At

In my Java project I am using the Google Drive API in order to download files from a public Drive.

When I try to list the children of a certain folder according to some criteria everything runs as expected. Yet there is this modifiedDate field which does not return any results. No error arises, but the list is empty, despite writing a perfectly reasonable search clause (there should be quite a sum of files).

This is my code:

    Drive.Children.List firstRequest = service.children().list(folderId)
            .setQ("mimeType='application/pdf' and modifiedDate <= '2016-03-07T19:17:54.759Z'" );
    do {
        ChildList result = firstRequest.execute();
        for(ChildReference child: result.getItems()) {
            File file = service.files().get(child.getId()).execute();
            System.out.printf("Found file: %s (%s): %s\n",
                    file.getTitle(), file.getId(), file.getCreatedDate());
        }
        firstRequest.setPageToken(result.getNextPageToken());
    } while (firstRequest.getPageToken() != null &&
            firstRequest.getPageToken().length() > 0);

Using the Try It! feature on the Google Developers' page the same query returns results as expected. The HTTP Request there is the following:

enter image description here

And this is the response: enter image description here

When I run my Java app this is the request URL:

GET  https://www.googleapis.com/drive/v2/files/0B3Y7hLeztp6SUVBCbnpRN0ZQVVU/children?q=mimeType%3D'application/pdf'%20and%20modifiedDate%20%3C%3D%20'2016-03-07T19:17:54.759Z'

The HTTP response is the following:

kind: drive#childList
etag: "TEeH8_qJkyJwjzQ-F4FJRbfwWxI/vyGp6PvFo4RvsFtPoIWeCReyIC8"
selfLink: https://www.googleapis.com/drive/v2/files/0B3Y7hLeztp6SUVBCbnpRN0ZQVVU/children?q=mimeType%3D'application/pdf'+and+modifiedDate+%3C%3D+'2016-03-07T19:17:54.759Z'
items: [


]

The requests are identical. But the responses are not... What could be the reason?

EDIT

I have to mention that I tried to use a service account. This will be a desktop application, so I didn't necessarily want users to acknowledge the use of the Google API and be compelled to create a Gmail address in case they didn't have one and authorize the requests. Moreover, the application only accesses resources on a drive shared publicly and needs no information about the client.

However, the service account key has caused my current problem, while using an OAuth Client ID key allows me to get the desired results.

Which is the recommended way to deal with this scenario? Or maybe I got everything wrong about the OAuth2 framework?

0

There are 0 answers