我尝试了几件事情,无法在Java Api v3中获取根文件夹标识。Google Drive API v3获取java文件夹中的根文件夹标识
我试了一下:
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();
我收到此错误:
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: ."
}
我看了migration文档和其他posts但还是没能得到根本的ID。谢谢!
只是好奇,为什么你需要根id? – codePG
我正在从API v2迁移到v3。前面的代码在多次调用中使用这个id,所以我试图获取id。 – user2640782
如果这可能有所帮助,在Try API [这里](https://developers.google.com/drive/v3/reference/files/get)中,我只为根目录中的文件做了'files.get',通过'父母'作为字段选项,我得到了'ID' – codePG