I’m trying to set up a file sharing system within my company using the Google Drive API. I’ve managed to create a spreadsheet and share it with everyone in our domain. The file creation works fine, and I can set the permissions correctly.
The problem is that while I can find the file as the creator, other users in the domain can’t see it when they search. I’ve tried using sharedWithMe=true in the query, but it doesn’t work.
What I really want is to replicate the ‘Shared with [domain]’ search functionality that’s in the Drive UI. Is there a way to do this with the API? I can’t find anything about source:domain in the docs.
Any ideas on how to make these shared files discoverable for all domain users would be super helpful!
hey, i’ve run into this before. try using the ‘corpora’ parameter in ur query. it lets u specify where to search. set it to ‘domain’ and it should find files shared with the whole domain. like this:
I’ve encountered this issue before when implementing a company-wide file sharing system. One approach that worked for me was utilizing the ‘driveId’ parameter in combination with the Team Drive API. This allows you to search within a specific shared drive that all domain users have access to.
First, create a Team Drive and add all domain users to it. Then, use the following query structure:
This method ensures all shared files are discoverable by domain users, as they’re searching within a common Team Drive. It’s a bit more setup initially, but provides better control and visibility in the long run.
I’ve dealt with a similar issue in my organization. The key is to use the ‘includeItemsFromAllDrives’ and ‘supportsAllDrives’ parameters in your API request. These allow you to search across all drives, including shared drives and files shared with the domain.
Here’s what worked for me:
drive.files.list({
q: "'domain.com' in domains and mimeType='application/vnd.google-apps.spreadsheet'",
includeItemsFromAllDrives: true,
supportsAllDrives: true,
fields: 'files(id, name)'
});
This query searches for spreadsheets shared with your domain. You might need to adjust the mimeType based on what you’re looking for.
Remember, there might be a delay between sharing a file and it appearing in search results. If it’s still not working, double-check your domain-wide sharing settings in the Google Admin console.