0

I am trying to get an id for an existing dir on Google Drive.

com.google.api.services.drive.model.About about = drive.about().get().execute();
  com.google.api.services.drive.Drive.Children.List list =
      drive.children().list(about.getRootFolderId());
  Iterator<Entry<String, Object>> itr = list.entrySet().iterator();
  Entry<String, Object> s;
  while (itr.hasNext()) {
    s = itr.next();
    System.out.println(s.getKey() + "::" + s.getValue());
  }

Right now this code is giving an output -

folderId::0APcEBFk-CF2pUk9PVA

which is probably not the correct id because I have 2 dirs and 3 files in my google drive. I must be missing something, what the right way to get the id of an existing dir.

I have seen this question, and it will be helpful if I can get an equivalent java example. I am using the same account's google drive which is owning the app.

Community
  • 1
  • 1
NRJ
  • 1,064
  • 3
  • 15
  • 32
  • are you sure you are using the latest client lib? that doesnt look anything like Googles Example of how to list files. https://developers.google.com/drive/v2/reference/files/list – Linda Lawton - DaImTo Dec 06 '14 at 10:51
  • 1
    @DaImTo because he's using the `children` API :) it looks like `files` is for searching content not navigating directories. – TWiStErRob Dec 06 '14 at 11:12

2 Answers2

0

Comparing your code to the example here you didn't call execute() on list, I think you're iterating on the request arguments.

Also it says:

folderId To list all files in the root folder, use the alias root as the value for folderId.

so you can skip getting the About.

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
0

Create a List of files and iterate.

Drive service = new Drive.Builder(httpTransport, jsonFactory, credential1).build();
String query = "'" + about.getRootFolderId() +"' " + "in parents";
List<File> files = service.files().list().setQ(query).execute().getItems();
return files; 

This should do.

Vinay Sheshadri
  • 361
  • 4
  • 13
  • Yes that worked. But it appears that it can only list the folders which are created programmatically. Any way to list a folder created via Drive UI ? – NRJ Dec 09 '14 at 14:16