如何列出Google云端硬盘共享文件夹中的文件并进行下载

时间:2019-01-30 13:34:17

标签: java android rest google-drive-api

我正在尝试列出Google云端硬盘共享文件夹并下载文件,该网址是我从G-Drive JAVA示例URL得出的:https://developers.google.com/drive/api/v3/quickstart/java

代码是:

public static void main(String... args) throws IOException, GeneralSecurityException {
        // Build a new authorized API client service.
        final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
                .setApplicationName(APPLICATION_NAME)
                .build();

        // 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.isEmpty()) {
            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());
            }
        }
    }

是否有可能在没有自律问题的情况下进行突击动作?

0 个答案:

没有答案