gpt4 book ai didi

android - Google Drive 从文件夹中获取文件

转载 作者:行者123 更新时间:2023-12-02 13:11:34 44 4
gpt4 key购买 nike

如何使用驱动器 api 从谷歌驱动器获取特定文件夹的文件列表

引用::https://developers.google.com/drive/android/deprecation
FileList

 public  Task<FileList> fetchLatestInformation(@NotNull String backupDir) {
return Tasks.call(mExecutor, () -> {
Drive.Files.List list = drive.files().list().setFields("nextPageToken, files(id, name, modifiedTime, size, createdTime, parents, appProperties)");
StringBuilder sb = new StringBuilder();
sb.append("mimeType = 'application/vnd.google-apps.folder' and name = '");
sb.append(backupDir);
sb.append("'");
list.setQ(sb.toString());
list.setPageSize(1000);
list.setOrderBy("modifiedTime");
return list.execute();
});
}
ActivityCode
    googleDrive.fetchLatestInformation(backupDir)
.addOnSuccessListener {
var files = it.files
files.reverse()
files.forEach {
Log.e(TAG,"file :: ${it?.name}")
}
var file = files.firstOrNull()

if (file != null) {
var time = file.modifiedTime
var date = Date(time.value)
var simpleDateFormat = SimpleDateFormat("EEE, dd MMM yyyy hh:mm aaa")
Log.e(TAG,"lastBackup name :: ${file.name}")
Log.e(TAG,"lastBackup date :: ${simpleDateFormat.format(date)}")
Log.e(TAG,"lastBackup size :: ${file.getSize()?.formatFileSize}")

}
}
.addOnFailureListener {
it.printStackTrace()
}
LogResult
E/BackupActivity: file :: AppBackup
E/BackupActivity: lastBackup name :: AppBackup
E/BackupActivity: lastBackup date :: Tue, 19 May 2020 10:44 PM
lastBackup size :: null

但是 AppBackup是包含备份文件 zips 的目录,所以我的问题是如何获取存储在 AppBackup 中的文件目录。

注意:: I AM USING DRIVE API V3

最佳答案

public  Task<FileList> fetchLatestInformation(@NotNull String parentFolderId) {
return Tasks.call(mExecutor, () -> {

Drive.Files.List list = drive.files().list().setFields("nextPageToken, files(id, name, modifiedTime, size, createdTime, parents, appProperties)");
StringBuilder sb = new StringBuilder();
sb.append("'");
sb.append(parentFolderId);
sb.append("'");
sb.append(" in parents and mimeType != 'application/vnd.google-apps.folder' and trashed = false");
list.setQ(sb.toString());
list.setPageSize(1000);
list.setOrderBy("modifiedTime");
return list.execute();
});
}
Children.List在 V3 中被删除,所以我们想使用 list() 我们可以使用 'parentFolderId' in parents and mimeType != 'application/vnd.google-apps.folder' and trashed = false 进行查询

在 v2 中, Children: list 用于列出文件夹的子文件夹并列出根文件夹的所有子文件夹,使用别名 root 作为 folderId 值。

但是,它在 Migrate to Google Drive API v3 中有说明。那 ChildrenParents收藏品已被删除。使用 files.list 反而。

引用 : How to search the folder in the google drive V3 using java?

关于android - Google Drive 从文件夹中获取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61897462/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com