Daniel Schneider
Daniel Schneider

Reputation: 3

Java - Google Drive API v3 - return specific fields for file - syntax

I am trying to get a large junk of Drive Files. I need to get the 3 Parameters emailAdress, displayName and modifiedTime. I only want to call the API once, to reduce processing time. However I cant figure out the syntax for the combined fields.

files = getDriveService().files().list()
                .setFields("files, permissions(emailAddress,displayName)")
                .setIncludeTeamDriveItems(true)
                .setSupportsTeamDrives(true).execute();

Gives me:

"code": 400,
"errors": [
    {
        "domain": "global",
        "location": "fields",
        "locationType": "parameter",
        "message": "Invalid field selection permissions",
        "reason": "invalidParameter"
    }
],
"message": "Invalid field selection permissions"

I`ve tried:

.setFields("files, permissions(emailAddress,displayName)")

.setFields("files(modifiedTime), permissions(emailAddress,displayName)")

.setFields("files/modifiedTime, permissions(emailAddress,displayName)")

.setFields("modifiedTime, permissions(emailAddress,displayName)")

.setFields("permissions(emailAddress,displayName)")
.setFields("modifiedTime")

Is it even possible to setFields() in combination with

.setSupportTeamDrives(true)

Thanks for your help.

Upvotes: 0

Views: 620

Answers (1)

Iamblichus
Iamblichus

Reputation: 19339

A Permission refers to who can access a file. It is connected to a specific file.

Because of this, permissions is a field of the File resource, not a field in Files.list response, so it's normal that you're not getting the desired outcome. So you should access permissions as a field inside files. The request should be like this:

.setFields("files(modifiedTime, permissions(emailAddress, displayName))")

I hope this is of any help.

Upvotes: 1

Related Questions