如何使用不建议使用的apis查找Google Apps Drive文档的完整路径 [英] how to find whole path of Google Apps Drive Documents using deprecated apis 3.0
问题描述
我正在使用Google Apps Drive APIs 3.0
.该API已弃用,但处于维护阶段.
I am using Google Apps Drive APIs 3.0
. This API is deprecated but it is in maintenance phase.
我想找到Google云端硬盘文档的路径. 例如test/test1/test2/test3/testDoc.txt
I want to find a path of Google Drive document. e.g. test/test1/test2/test3/testDoc.txt
截至目前,我已经能够检索所有文档,但没有目录路径. 我想显示驱动器文档的整个路径.
As of now, I am able to retrieve all the documents but without directory path. I want to show the whole path of a drive document.
我相信,没有API可以检索整个父路径或父链接.
现在不建议使用getFolders()
DocumentListEntry方法无法显示文件夹路径.
I believe, there is no API to retrieve the whole parent path or parent link.
getFolders()
method of DocumentListEntry is now deprecated is not able to show the folders path.
我调查发现,还有另一种方法getParentsLink()
只是显示了直接的父链接.它返回List.我无法在其上重复以再次找到其父链接.
I investigated and found that there is one more method getParentsLink()
which just shows immediate parent link. It returns List. On which I can not do re-iteration to find its parent link again.
public class MyClass {
private static final String DOCS_BASE_URL = "https://docs.google.com/feeds/";
private static final String DOCS_URL = "/private/full";
private static final String adminEmail = "admin@mytest.com";
private static final String password = "password";
private static final String projectKey = "MyProject";
public static void main(String[] args) {
try {
URL queryUrl = new URL(DOCS_BASE_URL + adminEmail + DOCS_URL);
DocumentQuery docQry = new DocumentQuery(queryUrl);
DocsService docService = new DocsService(projectKey);
docService.setUserCredentials(adminEmail, password);
docQry.setStringCustomParameter("showfolders", "true");
DocumentListFeed docFeed = docService.query(docQry, DocumentListFeed.class);
Iterator<DocumentListEntry> documentEntry = docFeed.getEntries().iterator();
while (documentEntry.hasNext()) {
DocumentListEntry docsEntry = documentEntry.next();
// Complex Logic to find whole directory path.(that I don't understand :P)
}
} catch (Exception exception) {
System.out.println("Error Occured " + exception.getMessage());
}
}
}
欢迎任何输入. 谢谢.
Any inputs are welcome. Thanks.
推荐答案
要解决此问题,您需要停止考虑文件夹和路径,而不再考虑标签(又称父级,又称集合).一个文件可以(可选)具有一个或多个标签/父项/集合.每个父级又可以具有一个或多个标签/父级/集合.因此,要获取文件的路径",您需要递归获取其父文件的父文件.请记住,一个文件可以有多个父级,每个父级也可以有多个父级,因此一个文件可以有多个路径.
To solve this you need to stop thinking in terms of folders and paths, and think in terms of labels (aka parents, aka collections). A file can (optionally) have one or more labels/parents/collections. Each parent can in turn have one or more label/parent/collection. So to get the "path" of a file, you need to recursively get the parents of its parent. Remember that a file can have multiple parents, each of which can also have multiple parents, thus a file can have multiple paths.
以您的示例"test/test1/test2/test3/testDoc.txt"为例,假设您具有testDoc.txt的ID,则可以获取它的DocumentListEntry,并调用getParentLinks,如果每个URL的DocumentListEntry的URL都返回此列表.它的父母,您的情况就是"test3".获取test3的DocumentListEntry,然后重复获取test2等.
Taking your example "test/test1/test2/test3/testDoc.txt", assuming you have the ID of testDoc.txt, you can get it's DocumentListEntry, and call getParentLinks which returns a list if URLs for the DocumentListEntry of each of its parents, in your case just "test3". Get the DocumentListEntry for test3, and repeat to get test2, etc.
这听起来可能很复杂,但是一旦您接受了要调用的文件夹的内容不是文件的容器,而仅仅是文件的属性,那就更有意义了.
It might sound complicated, but once you accept that the thing you're calling a folder is not a container of files, but simply a property of the file, it makes more sense.
这篇关于如何使用不建议使用的apis查找Google Apps Drive文档的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!