Google 驱动器 Android API 可以用来列出 google 驱动器上的所有文件吗?
Can Google Drive Android API be used to list all the files on google drive?
我想列出用户 google 驱动器上的所有文件(所有文件不仅仅是由应用程序创建的),然后下载选定的文件。我发现有两个 APIs Google Drive API for android 和 Google Drive REST API。经过大量搜索后,我知道我可以使用 REST API 获取文件列表,但不确定 Android API。请指导我如何进行。
Files.list can be used for Android as well. You can see that in this Android Quickstart
/**
* Fetch a list of up to 10 file names and IDs.
* @return List of Strings describing files, or an empty list if no files
* found.
* @throws IOException
*/
private List<String> getDataFromApi() throws IOException {
// Get a list of up to 10 files.
List<String> fileInfo = new ArrayList<String>();
FileList result = mService.files().list()
.setPageSize(10)
.setFields("nextPageToken, files(id, name)")
.execute();
List<File> files = result.getFiles();
if (files != null) {
for (File file : files) {
fileInfo.add(String.format("%s (%s)\n",
file.getName(), file.getId()));
}
}
return fileInfo;
}
我想列出用户 google 驱动器上的所有文件(所有文件不仅仅是由应用程序创建的),然后下载选定的文件。我发现有两个 APIs Google Drive API for android 和 Google Drive REST API。经过大量搜索后,我知道我可以使用 REST API 获取文件列表,但不确定 Android API。请指导我如何进行。
Files.list can be used for Android as well. You can see that in this Android Quickstart
/**
* Fetch a list of up to 10 file names and IDs.
* @return List of Strings describing files, or an empty list if no files
* found.
* @throws IOException
*/
private List<String> getDataFromApi() throws IOException {
// Get a list of up to 10 files.
List<String> fileInfo = new ArrayList<String>();
FileList result = mService.files().list()
.setPageSize(10)
.setFields("nextPageToken, files(id, name)")
.execute();
List<File> files = result.getFiles();
if (files != null) {
for (File file : files) {
fileInfo.add(String.format("%s (%s)\n",
file.getName(), file.getId()));
}
}
return fileInfo;
}