使用带有 Java 的 Google Drive API,如何仅列出 Drive Section/Folder 中的文件

2023-01-13Java开发问题
4

本文介绍了使用带有 Java 的 Google Drive API,如何仅列出 Drive Section/Folder 中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试获取 Google Drive 特定部分(驱动器部分)中的所有文件.

I am trying to get all files that are in a specific section of Google Drive (The Drive Section).

这些是我正在寻找的文件:

Those are the files I am looking for:

您可以看到一个名为 Projet 3 的文件夹和一个名为 Processus TP2 questions 的文件.在文件夹中我只有一个文件.

You can see a folder named Projet 3 and a file named Processus TP2 questions. In the folder I only have one file.

但是当我尝试列出所有文件时,我得到了数千个文件.如果我使用 Google Drive 顶部的搜索栏搜索它们,它会找到它们,但我不知道它们在哪里(可能是 Gmail 附件?).

But when I try to list all the files, I get thousands of files. If I search for them using the search bar on top of Google Drive, it finds them, but I have no idea where they are (maybe Gmail attachement?).

这是我的搜索查询:

FileList result = service.files().list()    
    .setQ("mimeType != 'application/vnd.google-apps.folder' 
            and trashed = false")    
    .setSpaces("drive")
    .setFields("nextPageToken, files(id, name, parents)")
    .setPageToken(pageToken)    
    .execute();

如何仅列出我可以在网络 UI 上的驱动器部分/文件夹中看到的文件?

How can I list only the files I can see in my Drive Section/Folder on the web UI?

非常感谢.

推荐答案

在查询中使用parents"属性,如下所示:

Use "parents" property in your query, like this:

FileList result = service.files().list()    
.setQ("'root' in parents and mimeType != 'application/vnd.google-apps.folder' and trashed = false")    
.setSpaces("drive")
.setFields("nextPageToken, files(id, name, parents)")
.setPageToken(pageToken)    
.execute();

如果您想列出特定文件夹的内容而不是根目录 - 在查询中使用该文件夹的 ID 而不是根目录".

If you want to list the contents of a specific folder rather than root - use that folder's id instead of 'root' in the query.

这篇关于使用带有 Java 的 Google Drive API,如何仅列出 Drive Section/Folder 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13