How to retrieve folder list from Google Drive using iOS SDK

I have successfully integrated the Google Drive SDK into my iOS application and can upload files without issues. Now I want to add a feature that lets users select which folder they want to upload their files to.

I managed to figure out how to get a list of all files from Google Drive, but I’m stuck on getting just the folders. I’ve looked through the documentation but haven’t found a clear solution.

I tried using this approach I found online, but it’s not working for me:

GTLQueryDrive *folderQuery = [GTLQueryDrive queryForFilesList];
folderQuery.q = @"mimeType='application/vnd.google-apps.folder' and trashed=false";

[self.googleDriveService executeQuery:folderQuery completionHandler:^(GTLServiceTicket *serviceTicket,
                                                          GTLDriveFileList *folderList,
                                                          NSError *requestError) {

    if (requestError == nil) {
        NSLog(@"Folders found: %@", folderList.items);
    } else {
        NSLog(@"Error retrieving folders: %@", requestError);
    }
}];

Is there a working method to fetch only folders from Google Drive using the iOS SDK?

Your code should work fine for retrieving folders. I had the same issue when I first tried this - usually it’s an auth scope problem or API version mismatch. Check that your app has the right Drive API scope set up. You need either full drive scope or at least drive.readonly to query folder metadata. Also make sure your GTLServiceDrive instance is authenticated before running the query. What helped me debug was adding more logging to see what actually got returned. Try logging the serviceTicket and check if folderList.items is empty vs nil. Sometimes the query runs fine but returns an empty array if there are permission issues or the user doesn’t have folders matching your criteria. Still having problems? Remove the trashed=false part temporarily to see if that helps, then add it back once you confirm the basic folder query works.

I’ve seen this before - it’s probably your query syntax. Try adding spaces around the operators: @"mimeType = 'application/vnd.google-apps.folder' and trashed = false". Google’s API gets picky about formatting. Also double-check that your GTLServiceDrive has the correct client ID from your console project.

The mime type filter looks good to me. I hit the same issue when I built folder browsing into my app last year. Adding the fields parameter fixed it for me - you need to tell the API exactly what data you want back. Without it, you won’t get complete folder info.

Try this:

folderQuery.fields = @"items(id,title,mimeType)";

Also make sure you’re testing with a Google account that actually has folders. The query returns nothing if the Drive’s empty or only has files in root. I wasted hours debugging before I realized I was using a fresh account with no folders.

One more thing - check you’re using the current API version. Lots of old tutorials reference deprecated methods that don’t work with newer SDKs.