简体   繁体   中英

Google Drive SDK - How to get the folder that a file is in?

I am currently trying to get the folder(s) that a Google Drive file is in using the Google Drive Java API. I understand I have to use ParentReference, but no "getName()" or "getTitle()" method is provided, and there is also no way to find out if a "File" (I am talking about the one in Google's API!) object is a folder.

Any help appreciated!

Your ParentReference is a ResourceId (file id). Once you have this ID, you can retrieve it's Title by calling

com.google.api.services.drive.Drive mGOOSvc;
...
mGOOSvc.files().get([parent ResourceId]).setFields("items(mimeType,title)").execute();

The best way to test it and figure out what fields to specify is at the bottom of this page - section called Try It!

The second question's answer (folder vs. file) is found in the 'mimeType' field of a GooDrive object .

"application/vnd.google-apps.folder".equalsIgnoreCase(mimeType);

If you have time to dig deeper, you may refer to this demo (createTree(), testTree()) that deals with issue of parents / children.

Good Luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM