本文介绍了如何从使用Java的谷歌驱动器获得完整的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java开发人员。我使用google应用程序client_id和client_secrect将谷歌驱动器集成到我的应用程序中。
基于这个client_id,我得到了用户的访问令牌。获得访问令牌后,我使用以下代码从驱动器获取文件和文件夹。

  HttpTransport httpTransport = new NetHttpTransport(); 
JacksonFactory jsonFactory = new JacksonFactory();
System.out.println(inventoryIntegrationConfig.getAccessToken());

GoogleCredential凭证=新的GoogleCredential()。setAccessToken(inventoryIntegrationConfig.getAccessToken());

Drive service = new Drive.Builder(httpTransport,jsonFactory,null)
.setApplicationName(Akoonu)
.setHttpRequestInitializer(凭证).build();

Files.List request = service.files()。list();




我成功接收到文件和文件夹下载网址和文件名。但我无法获取完整文件例如
BaseFolder / SubFolder1 / Subofsubfolder / testfile.txt。
在这里我的预期输出是路径:BaseFolder / SubFolder1 / Subofsubfolder /



我无法从任何Drive类获取完整文件路径。您可以告诉我如何获得完整的文件路径?
我们需要使用哪种方法来获得完整的文件路径?



请在这里帮我。

解决方案

没有方法调用/获取完整的文件路径。首先让我们澄清关于文件完整路径的一些细节。停止考虑文件夹和路径,并考虑像标签(父母和收藏)这样的字词。

A file can have more than one parent, each parent in turn can have one or more parent/label/collection. To get the "file path", we need to recursively get the parents of its parent. According to the SO ticket below answered by pinoyyid, "Remember that a file can have multiple parents, each of which can also have multiple parents, thus a file can have multiple paths."

Using Google Drive, disregard the terms path/folder but rather its simply just a property of a file.

Here is an Apps Script that created a workaround on getting the parents/collection of the file and a related SO question for further information. I hope it helps.

这篇关于如何从使用Java的谷歌驱动器获得完整的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 00:56