I have an app where users (using the drive.file Oath scope) can create a new Sheet. I want to display the Google Picker to display the Sheets they've created with my app BUT the Picker is showing ALL of their Sheets. Since the Oath scope is drive.file I only have permission to open Sheets created by my app. Therefore, I only want to display Sheets in the Picker that were created by my app. If they select a Sheet not created by my app they will be confused when they try to open it and they can't. They'll think my website is broken.
I've tried the following:
const docsView = new (window.gapi as any).picker.api.DocsView(
ViewId.SPREADSHEETS
);
picker = new PickerBuilder()
.addView(docsView)
.setOAuthToken(accessToken)
.setOrigin(window.location.origin)
.setAppId(GOOGLE_CLOUD_PROJECT_NUMBER);
The key part is setAppId which doesn't seem to do anything...I've tried the project name, project ID, client ID but nothing seems to work. I've also tried setting //.setQuery(`appDataFilter:${GOOGLE_CLOUD_PROJECT_NUMBER}`); but that doesn't seem to work either and gives me NO files in the picker.
EDIT: I've also tried setQuery('appProperties has { key="creatorAppId" and value="my-project-number" }'); with no luck
The Google Picker cannot filter by “files created by my app” (drive.file) out of the box. The Picker’s Drive view does not support Drive v3 query syntax (like appProperties) nor any “creatorAppId” filter. The setAppId and setQuery you tried won’t achieve this.
What you can do instead:
Use a dedicated folder for your app’s files, then point the Picker to that folder.
When you create the spreadsheet, place it in a known folder (e.g., “MyApp Sheets”).
In the Picker, use DocsView.setParent(folderId) so users only see files inside that folder.