我嘗試了幾件事情,無法在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