# How to Automate Google Drive File Sharing using the API

- Tool: API Automations
- Difficulty: Intermediate
- Fix time: 45–90 minutes
- Compatibility: Google Drive API v3, google-api-python-client 2.x, googleapis npm 144.x
- Last updated: May 2026

## TL;DR

Use Google Drive API v3 permissions.create to programmatically share files and folders with users, groups, or domains. The key gotcha: always pass supportsAllDrives=true for Shared Drives or you get 404s. The drive.file scope only sees app-created files — you need the Restricted drive scope to share files the user already owns. Watch for the separate sharingRateLimitExceeded 403 error that has a stricter limit than the standard quota.

## Best practices

- Always pass supportsAllDrives=true on every Drive API call that might involve Shared Drive files — make it a default parameter in your helper functions
- Separate sharing into smaller batches with delays instead of firing all permission creates concurrently — the sharingRateLimitExceeded limit hits before the main quota
- Use drive.file scope and create files through your app when possible — this avoids needing the Restricted drive scope and its OAuth audit requirements
- Prefer folder-level sharing over file-level sharing: share the parent folder once rather than each file individually, both for cleaner permissions and fewer API calls
- Store permission IDs (not emails) when you need to revoke later — the delete endpoint requires the ID, not the email address
- Include the fields parameter on all responses to avoid fetching unnecessary data and reduce quota consumption
- Implement idempotency: before sharing, check if the permission already exists with permissions.list to avoid duplicate permission errors and unnecessary API calls
- For DWD Service Accounts, add quotaUser parameter to distribute quota per impersonated user rather than burning all quota on the service account identity

## Frequently asked questions

### Why do I get a 404 error when trying to share a file in a Shared Drive?

You're missing supportsAllDrives=true on the request. Shared Drive files return 404 (not a permission error) when this parameter is absent. Add supportsAllDrives=true to every Drive API call that might touch Shared Drive files — permissions.create, files.get, files.list, and files.update all need it.

### What is the difference between sharingRateLimitExceeded and rateLimitExceeded?

These are two separate limits. rateLimitExceeded is the standard quota limit (1,000,000 units/min per project). sharingRateLimitExceeded is a stricter limit specifically for permission creation operations — it can trigger even when you have plenty of quota remaining. Handle them separately in your error logic, and use delays between sharing operations proactively, not just on error.

### Can a service account share files without user impersonation?

Service accounts cannot own files on My Drive (they have no storage). They can create files on Shared Drives, and they can share those files. For My Drive operations, you must use Service Account + Domain-Wide Delegation to impersonate a real user. The service account then acts as that user and shares from the user's context.

### What is the difference between drive.file scope and drive scope?

drive.file is Non-sensitive and only shows files your app created OR that the user explicitly opened via the Google Picker UI. It cannot list or access files the user already owns unless they opened them through your app. drive is Restricted and can see everything the user owns — but it requires OAuth verification and a CASA security audit, which is a multi-week process.

### How do I share a folder so all files inside it are automatically shared too?

In Google Drive, permissions are inherited: sharing a folder gives access to all its current and future contents. Call permissions.create once on the folder with the desired role, and the grantee gets access to everything inside. You do NOT need to share each file individually. This is the recommended approach — both for cleaner permission management and fewer API calls.

### Can RapidDev help set up a Google Drive sharing automation for my business?

Yes. If you need a complete onboarding automation — creating client folders, uploading documents, and sharing them automatically when a contract is signed — RapidDev can build this end-to-end. We handle the OAuth setup, Shared Drive configuration, and rate limit management so you don't have to.

### How do I revoke access for a user who is leaving the company?

You cannot revoke by email directly. First call permissions.list on the file or folder to get the permission ID for that user's email address, then call permissions.delete with that permission ID. If you need to revoke access across many files, you'll need to iterate through all files, list permissions on each, find the matching permission by email, and delete it — there is no bulk revocation endpoint.

---

Source: https://www.rapidevelopers.com/api-automations/how-to-automate-google-drive-file-sharing-using-the-api
© RapidDev — https://www.rapidevelopers.com/api-automations/how-to-automate-google-drive-file-sharing-using-the-api
