Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

android - Listing files and folders of GDrive using Google Drive 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);
     }
 });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...