You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SearchFile.java sample code needs to be updated for API v3? #1547
I tried running the Java sample code in the file SearchFile.java on the official doc page, which is also stored here.
That code fails for me with this error output:
GET https://www.googleapis.com/drive/v3/files?fields=nextPageToken,%20items(id,%20title)&spaces=drive
{
"code": 400,
"errors": [
{
"domain": "global",
"location": "fields",
"locationType": "parameter",
"message": "Invalid field selection items",
"reason": "invalidParameter"
}
],
"message": "Invalid field selection items"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:118)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:37)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$3.interceptResponse(AbstractGoogleClientRequest.java:479)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1111)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:565)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:506)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:616)
The key part of that error message is Invalid field selection items
It took me a while to realize that this line of code in SearchFile.java is the offender: .setFields("nextPageToken, items(id, title)")
I think that "items" is a API V2 term, whereas I am using the modern API V3, in which case that line needs to be changed to something like .setFields("nextPageToken, files(name, id)")
Activity