Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Drive not listing files in folder
    text
    copied!<p>Google Drive is not listing files in a folder when I give the folder id, nor when I give a mime type. It works for files in root folder with empty query. How do I list files in a folder?</p> <p>Code: </p> <pre><code>public ArrayList&lt;String&gt; getDriveList(String folder, String folderId) throws IOException { // Create a new authorized API client HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); Credential credential = Utils.getCredential(); Drive service = new Drive.Builder(httpTransport, jsonFactory, credential) .setApplicationName("SDM Mailer App") .build(); ArrayList&lt;File&gt; result = new ArrayList&lt;File&gt;(); // String query = ""; String query = "'"+folderId+"' in parents"; // String query = "mimeType = 'application/vnd.ms-excel'"; // String query = "'"+folderId+"' in parents and mimeType = 'application/vnd.ms-excel'"; log.info("Finding files with query: " + query); Drive.Files.List request = service.files().list().setQ(query); do { try { FileList files = request.execute(); result.addAll(files.getItems()); request.setPageToken(files.getNextPageToken()); } catch (IOException e) { System.err.println("An error occurred: " + e); request.setPageToken(null); } } while (request.getPageToken() != null &amp;&amp; request.getPageToken().length() &gt; 0); log.info("Found # results: " + result.size()); ArrayList&lt;String&gt; resultPlain = new ArrayList&lt;String&gt;(); for (File f: result) { resultPlain.add(f.getTitle()); } return resultPlain; } // driveList </code></pre> <p>Log:</p> <pre><code>INFO: Finding files with query: '0B72jLeZWY3rsQllNMWhCQWhtLWc' in parents Oct 04, 2013 8:50:42 PM com.example.server.SDMServiceImpl getDriveList INFO: Found # results: 0 </code></pre> <p>or with empty query, root folder:</p> <pre><code>INFO: Finding files with query: Oct 04, 2013 9:20:05 PM com.example.server.SDMServiceImpl getDriveList INFO: Found # results: 2 </code></pre> <p>Drive Files: </p> <p><img src="https://i.imgur.com/DLRGclO.png" alt="Imgur"></p> <p>Reference Documentation: </p> <p><a href="https://google-developers.appspot.com/drive/search-parameters" rel="nofollow noreferrer">https://google-developers.appspot.com/drive/search-parameters</a></p> <p>JAR: </p> <p>google-api-services-drive-v2-rev102-1.16.0-rc.jar</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload