简体   繁体   English

如何从Google Drive API V3获取文件列表?

[英]How to get list of files from google drive api v3?

I want to get list of files from google drive folder using google drive apis. 我想使用Google Drive API从Google Drive文件夹中获取文件列表。

I have referred this stack overflow question 我已经提到了这个堆栈溢出问题

Above is not working for v3 apis. 以上不适用于v3 API。 I think they have removed that support in version 3. I also referred this doc But it is not clear how it works. 我认为他们已经删除了版本3中的支持。我也提到了此文档,但尚不清楚它是如何工作的。

I am using java sdk. 我正在使用Java SDK。

Take a look at version 3 (v3): 看一下版本3(v3):

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

There is some example Java code (do search for "public class Quickstart"). 有一些Java代码示例(搜索“ public class Quickstart”)。

Looking at the main method - you get a Drive, and can then page "through" files using: 查看主要方法-获得驱动器,然后可以使用以下方法分页“浏览”文件:

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

Here is the main method: 这是主要方法:

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());
        }
    }
}

This should work with udpdated URI: 这应该与udpdated URI一起使用:

GET https://www.googleapis.com/drive/v3/files

You could try the online demo with OAuth at https://developers.google.com/drive/v3/reference/files/list where you will find some more information on how to use the API and the OAuth. 您可以在https://developers.google.com/drive/v3/reference/files/list上尝试使用OAuth进行在线演示,在此您将找到有关如何使用API​​和OAuth的更多信息。

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

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