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()
On this support documentation it is stated that the drive.file scope:
Creates new Drive files, or modify existing files, that you open with an app or that the user shares with an app while using the Google Picker API or the app's file picker.
Also, a community member from this public forum stated that:
Using
drive.file
, then selecting a folder, doesn't give you access to what documents are in that folder. It only gives access to the folder itself.
A possible workaround for this involves using the scope (which you confirmed was working when I asked in the comments):
since it grants full read and write access to all files and folders
in the user's Google Drive.
Keep in mind that the sensitivity of this Drive API scope is under Restricted meaning:
These scopes provide wide access to Google User Data and require you to go through a restricted scope verification process. For information on this requirement, see Google API Services User Data Policy and Additional Requirements for Specific API Scopes. If you store restricted scope data on servers (or transmit), then you must go through a security assessment.
This means that the scope technically provides the full access you need but it involves a time consuming OAuth verification process for security purposes.