I’m building an app that needs to read all files from a folder that users pick through Google Picker. The user should be able to choose any folder they want using the picker interface.
I’ve been looking at the Google Drive API documentation about scopes and permissions. It seems like the drive.file scope might work for what I need. But I’m stuck on one thing - how do I set up my backend code to actually access the specific files that users select on the frontend?
The flow I want is: user picks folder in frontend → backend gets access to read all files in that folder. I’m not sure how to connect these two parts together. Has anyone done something similar before?
hey! so yeah, just send the folder ID from the picker to your backend along with the OAuth token. use drive.readonly scope for safer read-only access. managing the token can be tricky, so make sure you handle it securely between your frontend and backend.
The drive.file scope won’t work here - it only gives you access to files your app created or ones the user explicitly opened. Use drive.readonly instead to read files from user-selected folders. When someone picks a folder through the Picker, you’ll get its ID. Send that ID and the user’s access token to your backend. Your backend can then hit the Drive API’s files.list endpoint with '[folder_id]' in parents to grab all files in that folder. Don’t forget to handle token refresh since access tokens die after an hour. Store the refresh token securely on your backend so everything keeps running smoothly.
Hit this same issue last year building a document management tool. You need proper OAuth flow with your backend handling the authorization. Once the user picks a folder through the Picker, grab the folder ID and make sure your backend has a valid access token for that session. Heads up - nested folders tripped me up. You’ll probably want recursive folder traversal if users expect files from subfolders. Drive API has rate limits too, so for large folders, use pagination and exponential backoff. The auth handoff between frontend and backend was a pain to debug, but once you nail the token management, file enumeration is cake.