如何从Java中的Google Drive API获取JSON中所有文件夹中的所有文件

如何从Java中的Google Drive API获取JSON中所有文件夹中的所有文件,java,json,google-drive-api,Java,Json,Google Drive Api,是否有机会使用Google Drive API获取JSON中所有文件夹中的所有文件,只需使用sending get方法即可?是的,这是可能的。您可以使用文件。列表。 这是相应的GET请求,默认情况下返回所有文件 GET https://www.googleapis.com/drive/v2/files 仔细看看。还有一个在线演示来测试它 此请求的Java代码可能如下所示: private static List<File> retrieveAllFiles(Drive servic

是否有机会使用Google Drive API获取JSON中所有文件夹中的所有文件,只需使用sending get方法即可?

是的,这是可能的。您可以使用
文件。列表
。 这是相应的GET请求,默认情况下返回所有文件

GET https://www.googleapis.com/drive/v2/files
仔细看看。还有一个在线演示来测试它

此请求的Java代码可能如下所示:

private static List<File> retrieveAllFiles(Drive service) throws IOException {
    List<File> result = new ArrayList<File>();
    Files.List request = service.files().list();

    do {
      try {
        FileList files = request.execute();

        result.addAll(files.getItems());
        request.setPageToken(files.getNextPageToken());
      } catch (IOException e) {
        System.out.println("An error occurred: " + e);
        request.setPageToken(null);
      }
    } while (request.getPageToken() != null &&
             request.getPageToken().length() > 0);

    return result;
  }
私有静态列表检索所有文件(驱动器服务)引发IOException{
列表结果=新建ArrayList();
Files.List请求=service.Files().List();
做{
试一试{
FileList files=request.execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
}捕获(IOE异常){
System.out.println(“发生错误:“+e”);
request.setPageToken(null);
}
}while(request.getPageToken()!=null&&
request.getPageToken().length()>0);
返回结果;
}