如何使用 Java 检测文件是否存在于 Google Drive 中(并且未被删除)?

2024-06-28

非常不言自明的标题。我正在使用适用于 Java 的 Google Drive Client Api。我目前拥有的内容如下:

File f = mService.files.get(fileId).execute();

但是,我找不到该房产File用于检查文件是否已被删除。File.getExplicitlyTrashed()为我提供了已删除和未删除文件的 null 值。


The trashed属性隐藏在里面File.Labels https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/model/File.Labels.html类,您可以从中获得File.getLabels() https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/model/File.html#getLabels()。一个有效的例子是:

public boolean validFileId(String id) {
    try {
        File f = mService.files().get(id).execute();
        return !f.getLabels().getTrashed();
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("bad id: " + id);
    }
    return false;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Java 检测文件是否存在于 Google Drive 中(并且未被删除)? 的相关文章

随机推荐