清单使用谷歌云端硬盘API文件和的GDrive的文件夹内 [英] Listing files and folders of GDrive using Google Drive Api
问题描述
我想列出使用谷歌云端硬盘API在谷歌硬盘的一个目录下的所有文件和文件夹。但我只得到文件的元数据对象不在目录中的文件夹present的。我使用下面的code
DRIVEFOLDER文件夹= Drive.DriveApi.getRootFolder(getClient());
folder.listChildren(getClient())
.setResultCallback(新ResultCallback< DriveApi.MetadataBufferResult>(){@
覆盖
公共无效onResult(DriveApi.MetadataBufferResult结果){
如果(!result.getStatus()。isSuccess()){
L.C(错误清单根文件夹);
返回;
}
MetadataBuffer metadataBuffer = result.getMetadataBuffer();
元数据FILEDATA;
列表项[] =项新的ListItem [metadataBuffer.getCount()];
L.C(伯爵:+ metadataBuffer.getCount());
的for(int i = 0; I< metadataBuffer.getCount();我++){
项目由[i] =新的ListItem(metadataBuffer.get(I));
}
listAdapter =新ArrayAdapter<列表项> (ExplorerClass.this,android.R.layout.simple_list_item_1,项目);
mainList.setAdapter(listAdapter);
}
});
如果不是由您的应用程序创建或前,您的应用程序打开该目录中的文件夹或文件present(你的情况根),你赢了'T能看到他们的应用程序。这是因为您可能正在使用Drive.FILE范围: https://developers.google.com/drive / WEB /示波器
不幸的是,谷歌的Android的驱动API目前仅支持drive.file和drive.appfolder范围。如果你需要drive.readonly.metadata范围可以使用谷歌驱动器REST API。
I want to list all files and folders of a directory on Google Drive using Google Drive API. But I am only getting Metadata object of files not of the folders present in the directory. I am using the following code
DriveFolder folder = Drive.DriveApi.getRootFolder(getClient());
folder.listChildren(getClient())
.setResultCallback(new ResultCallback < DriveApi.MetadataBufferResult > () {@
Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
L.c("Error in listing root folder");
return;
}
MetadataBuffer metadataBuffer = result.getMetadataBuffer();
Metadata filedata;
ListItem[] items = new ListItem[metadataBuffer.getCount()];
L.c("Count :" + metadataBuffer.getCount());
for (int i = 0; i < metadataBuffer.getCount(); i++) {
items[i] = new ListItem(metadataBuffer.get(i));
}
listAdapter = new ArrayAdapter < ListItem > (ExplorerClass.this, android.R.layout.simple_list_item_1, items);
mainList.setAdapter(listAdapter);
}
});
If the folders or files present in the directory (in your case root) were not created by your app or opened by your app before, you won't be able to see them with your app. This is because you are probably using Drive.FILE scope: https://developers.google.com/drive/web/scopes
Unfortunately, the google drive android API currently supports only drive.file and drive.appfolder scopes. You can use the Google Drive REST API if you need drive.readonly.metadata scope.
这篇关于清单使用谷歌云端硬盘API文件和的GDrive的文件夹内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!