【发布时间】:2017-01-05 11:24:06
【问题描述】:
我尝试了几件事,但无法在 Java Api v3 中获取根文件夹 ID。
我尝试了什么:
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: ."
}
【问题讨论】:
-
只是好奇,为什么需要root id?
-
我正在从 API v2 迁移到 v3。前面的代码在多次调用中使用了这个 id,所以我试图获取 id。
-
如果这有帮助,在 Try API here 中,我只是为根目录中的一个文件做了
files.get并将parents作为字段选项传递,我得到了ID跨度> -
感谢您的解决方案,我会尝试的。但是,在迁移文档中它说“对于 rootFolderId,使用 fileId=root 和 ?fields=id 执行 files.get”。你知道我怎样才能得到这份工作吗?
-
是的,刚刚尝试了您的建议。 file.get("root").setFields("id") 可能是个不错的尝试。
标签: java google-drive-api