【问题标题】:What libraries I have to use for uploading the files to GOOGLE DRIVE我必须使用哪些库将文件上传到 GOOGLE DRIVE
【发布时间】:2016-10-29 02:22:34
【问题描述】:

我找到了将文件上传到 Google Drive 的示例:

File fileMetadata = new File();
fileMetadata.setName("My Report");
fileMetadata.setMimeType("application/vnd.google-apps.spreadsheet");

java.io.File filePath = new java.io.File("files/report.csv");
FileContent mediaContent = new FileContent("text/csv", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());

问题是我不能使用它。我在哪里可以找到允许编译该代码的库? 我的 Eclipse 不知道 File() 和 driveService 类。

【问题讨论】:

标签: java upload google-api google-drive-api


【解决方案1】:

在此处关注Java Quickstart 获取 Google Drive REST API - https://developers.google.com/drive/v3/web/quickstart/java

上述链接中的步骤摘要-

开发环境 - Java 1.7+、Gradle 2.3+、启用 Google Drive 的 Google 帐户

第一步:Google Developers ConsoleTurn on the Drive API创建一个项目

第 2 步:准备项目 - 下载所需的依赖项,设置您的 gradle 构建

以下库是特别需要的

compile 'com.google.api-client:google-api-client:1.22.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.22.0'
compile 'com.google.apis:google-api-services-drive:v3-rev48-1.22.0'

第 3 步: 设置样本;编写代码来验证您的应用以将文件上传到用户的 Google 云端硬盘

第 4 步:运行示例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-10
    • 2015-09-13
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多