【发布时间】:2016-05-18 08:39:07
【问题描述】:
我已经在谷歌驱动器中创建了一个服务帐户,用于从服务器上传谷歌驱动器中的文件并稍后下载这些文件。但是,当我尝试获取文件夹的文件列表并获取这些文件的 webContentLinks 时,它返回 null。我检查了它的其他一些属性,它为getWebContentLink() 和getWebViewLink() 返回null,除了文件名和文件ID。
谁能帮我获得webContentLink,或者你能找出我为什么无法获得webContentLink的问题。
这是我尝试过的部分代码:
List<String> linkList=new ArrayList<String>();
fileFlag=0;
pageToken = null;
do {
driveFiles = service.files().list()
.setQ("mimeType!='application/vnd.google-apps.folder and "+childFolder.getId()+"' in parents ")
.setSpaces("drive")
.setFields("nextPageToken, files(id, name)")
.setPageToken(pageToken)
.execute();
System.out.println("\n\nFile No. : "+driveFiles.getFiles().size());
for(com.google.api.services.drive.model.File file: driveFiles.getFiles()) {
linkList.add(file.getWebContentLink());
System.out.println(file.getName());
System.out.println("File Link : "+file.getWebContentLink());
System.out.println(file.getId());
System.out.println(file.getWebViewLink());
}
pageToken = driveFiles.getNextPageToken();
} while (pageToken != null);
这是输出之一
File No. : 4
V2__data.sql
File Link : null
0BzCRyzakN8eJOGRTODhXTFkxUWc
null
V1__table.sql
File Link : null
0BzCRyzakN8eJT09BbG5JUFdNYmc
null
V2__data.sql
File Link : null
0BzCRyzakN8eJa0FyUGw3UFZJZ00
null
V1__table.sql
File Link : null
0BzCRyzakN8eJcDJNWHY4cFNHMW8
null
【问题讨论】:
-
我认为您对this thread 有同样的问题。看看吧,也许有帮助。
-
我已经检查了那个线程。但是 webContentLink 甚至不适用于小文件。由于该方法将在 8 月 16 日之后禁用,因此我无法使用该方法。 webContentLink 的值为空。这是我的主要问题。 @noogui
-
Service Account 没有 Web API,所以可能这就是没有 webcontentUrl 的原因。你想做什么?尝试查找 downloadUrl 或 expoertLinks。
-
我正在寻找downloadUrl。 @pinoyyid
-
@For_A_While 你正在调用“setFields(files(id, name)”,所以你告诉驱动器只返回 id 和 name 属性。因此所有其他属性都将为空。跨度>
标签: java google-drive-api