I tried several things bu couldn't get the root folder id in Java Api v3.
What I tried:
String id = service.files().get("fileId=root").setFields("id").execute().getId();
String id = service.files().get("fileId=root").setFields("?fields=id").execute().getId();
String id = service.files().get("root").setFields("?fields=id").execute().getId();
String id = service.files().get("fileId=root and ?fields=id").execute().getId();
I am getting this errors:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "fields",
"locationType" : "parameter",
"message" : "Invalid field selection ?fields=id",
"reason" : "invalidParameter"
} ],
"message" : "Invalid field selection ?fields=id"
}
An error occurred: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"location" : "fileId",
"locationType" : "parameter",
"message" : "File not found: .",
"reason" : "notFound"
} ],
"message" : "File not found: ."
}
I looked the migration document and other posts but still couldn't get the root id. Thanks!
Try the following combination to see if that works.
String id = service.files().get("root").setFields("id").execute().getId();
To execute the above combination, you have to give your application full access to use Drive. OAuth 2.0 scope that needs to be given: https://www.googleapis.com/auth/drive or https://www.googleapis.com/auth/drive.readonly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With