简体   繁体   English

Google云端硬盘SDK-如何获取文件所在的文件夹?

[英]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. 我目前正在尝试使用Google Drive Java API获取Google Drive文件所在的文件夹。 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. 我知道我必须使用ParentReference,但是没有提供“ getName()”或“ getTitle()”方法,也没有办法查明是否有“文件”(我正在谈论Google API中的那个)! )对象是一个文件夹。

Any help appreciated! 任何帮助表示赞赏!

Your ParentReference is a ResourceId (file id). 您的ParentReference是ResourceId(文件ID)。 Once you have this ID, you can retrieve it's Title by calling 拥有此ID后,您可以通过调用

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 . 在GooDrive对象的'mimeType'字段中找到第二个问题的答案(文件夹还是文件)。

"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. 如果您有时间进行更深入的研究,则可以参考此示例 (createTree(),testTree()),该示例涉及父母/子女的问题。

Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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