Selecting a folder in the Google Picker with the drive.file scope

Selecting a folder in the Google Picker with the drive.file scope
typescript
Ethan Jackson

Google is pushing developers to use the drive.file scope instead of the drive.readonly scope (which is restricted) while encouraging the use of the Google picker.

Using the Google picker and drive.file scope, I can construct a picker to select a folder. But this appears to be a useless approach, as I don't get access to any of the files in the folder. This feels broken to me.

Google, is this intentional? Clearly the user is trying to give access to the folder and its contents.

Google Picker, filtered to folders

Code to launch the picker:

const view = new google.picker.DocsView( google.picker.ViewId.FOLDERS, ).setMode(google.picker.DocsViewMode.LIST); const picker = new google.picker.PickerBuilder() .enableFeature(google.picker.Feature.NAV_HIDDEN) .setAppId(projectNumber) .setOAuthToken(accessToken) .addView(view) .setDeveloperKey(apiKey) .setCallback(pickerCallback) .setTitle('Select folders') .build(); picker.setVisible(true);

Code that attempts to find the files in the picked folder:

driveClient .files() .list() .setQ("'$folderId' in parents and trashed = false") .setFields("nextPageToken, files(id, name, mimeType)") .setSupportsAllDrives(true) .setIncludeItemsFromAllDrives(true) .setPageToken(pageToken) .execute()

Answer

drive.file scope is fine even with folders as long as you select the folder along with the token you access all files inside that folder and sub folder . but in the client you cant access folder contents so yes its intentional

Related Articles