简体   繁体   English

从Google云端硬盘下载文件-方法丢失? (java)

[英]Download file from Google Drive - method is missing? (java)

I try to use the Java API of Google Drive to download all files in a certain folder. 我尝试使用Google云端硬盘的Java API下载某个文件夹中的所有文件。 Since I am beginner with this API I googled and found several questions and answers about this here on SO, ee, Download files from google drive using java API 由于我是使用此API的初学者,因此我在google上搜索并找到了关于此的一些问题和答案,ee, 使用Java API从Google驱动器下载文件

All these examples use the following construction: 所有这些示例都使用以下构造:

if (file.getDownloadUrl() !=null && file.getDownloadUrl().length() > 0) {

However, when I use this (in Eclipse) (it is of course simplified) 但是,当我在Eclipse中使用它时(当然是简化的)

com.google.api.services.drive.model.File myFile = new com.google.api.services.drive.model.File();
myFile.getDownloadUrl();

I get an error message The method getDownloadUrl() is undefined for the type File . 我收到一条错误消息The method getDownloadUrl() is undefined for the type File Furthermore, googling for this method name does not reveal any meaningful results. 此外,对该方法名称进行谷歌搜索不会显示任何有意义的结果。 Am I missing something very fundamental here? 我在这里错过了一些非常基本的东西吗?

Firstly, com.google.api.services.drive.model.File myFile = new com.google.api.services.drive.model.File(); myFile.getDownloadUrl(); 首先, com.google.api.services.drive.model.File myFile = new com.google.api.services.drive.model.File(); myFile.getDownloadUrl(); com.google.api.services.drive.model.File myFile = new com.google.api.services.drive.model.File(); myFile.getDownloadUrl(); makes no sense. 没有意义。 You are trying to assign a String (the return value of getDownloadUrl()) to a File object. 您试图将一个String(getDownloadUrl()的返回值)分配给File对象。

However, the compiler hasn't got round to complaining about this yet because it can't find the downloadUrl() method signature. 但是,编译器尚未对此抱怨,因为它无法找到downloadUrl()方法签名。 My guess is that you are using the wrong jar file for the API. 我的猜测是您为API使用了错误的jar文件。 In this case I think you're trying to use the v2 API but have probably downloaded the v3 jar. 在这种情况下,我认为您正在尝试使用v2 API,但可能已经下载了v3 jar。 It is better to follow the Google documentation rather than copy/paste code from StackOverflow. 最好遵循Google文档,而不要从StackOverflow复制/粘贴代码。

The method file.getDownloadUrl() has been removed in Drive API v3. 在Drive API v3中已删除方法file.getDownloadUrl()
Try to use the method executeMediaAndDownloadTo() instead of using getDownloadUrl() in order to download google drive files. 尝试使用方法executeMediaAndDownloadTo()而不是使用getDownloadUrl()来下载Google驱动器文件。 See the following sample code . 请参见以下示例代码

The method executeMediaAndDownloadTo() in the Drive.File.Get class . Drive.File.Get类中的方法executeMediaAndDownloadTo()

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

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