java - 如何从 google Drive api v3 获取文件列表?

标签 java google-drive-api

我想使用 Google Drive api 从 Google Drive 文件夹中获取文件列表。

我已经提到过这个 stack overflow question

以上不适用于 v3 api。我认为他们已经在版本 3 中删除了该支持。 我还提到了这个doc 但尚不清楚它是如何工作的。

我正在使用java sdk。

最佳答案

看看版本 3 (v3):

https://developers.google.com/drive/v3/web/quickstart/java

有一些 Java 代码示例(请搜索“public class Quickstart”)。

查看主要方法 - 您获得一个云端硬盘,然后可以使用以下方法“浏览”文件:

FileList result = service.files().list()
         .setPageSize(10)
         .setFields("nextPageToken, files(id, name)")
         .execute();

主要方法如下:

public static void main(String[] args) throws IOException {
    // Build a new authorized API client service.
    Drive service = getDriveService();

    // Print the names and IDs for up to 10 files.
    FileList result = service.files().list()
         .setPageSize(10)
         .setFields("nextPageToken, files(id, name)")
         .execute();
    List<File> files = result.getFiles();
    if (files == null || files.size() == 0) {
        System.out.println("No files found.");
    } else {
        System.out.println("Files:");
        for (File file : files) {
            System.out.printf("%s (%s)\n", file.getName(), file.getId());
        }
    }
}

关于java - 如何从 google Drive api v3 获取文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44655239/

相关文章:

android - 如何使用 DriveApi 从谷歌驱动器下载选定的文件?

google-apps-script - 与其他用户共享 Google App 脚本 - 请求权限并授权脚本

java - 如何更好地改变java项目中处理异常的方式?

java - WinAppDriver 如何在 Java 中定义 WindowsElement 而不会出现 java.lang.ClassCastException

java - Spring http 客户端 : pkcs12 keystore and trustsrtore on httpclient

android - Google 云端硬盘向我的 Android 应用程序返回错误 400 或 403?

flutter - 如何在 Flutter 中播放 Google Drive 中的音乐(mp3、m4a 等)

Java字节数据类型

java - 将 System.out.print 转换为 JOptionPane?

java - 查找所需的 jar 时出现问题 Google Drive V3 与 Java 集成