name: gdown-public-drive-access
description: Access public Google Drive folders without OAuth using gdown Python package
category: devops
Access Public Google Drive Folder Without OAuth
When to use
Need to access a Google Drive folder but:
- - OAuth is complex (browser-based, needs human confirmation)
- - rclone token expired and can't reconnect without browser
- - gcloud not installed
- - No Service Account access
- - Drive folder can be made public
- -
gdown --folder --jsonstill works (lists files) - - Individual file download fails:
Error: Cannot retrieve the public link - -
gdown --folder -Otimes out - -
rclone: Token expires, reconnect requires browser OAuth (can't automate) - - Google OAuth via
gdown --oauthorrclone config: Needs human confirmation, can't be done headlessly - -
gcloud: Not installed on VPS - - Service Account: Requires Google Cloud Console access
- - Works for publicly shared folders only
- - Works for files shared with "anyone with the link"
- -
gdownuses requests under the hood — no special Drive API scopes needed - - For large folders, use
--continueflag to resume interrupted downloads - -
gdown --folder -Ocan timeout on large folders — use--jsonto list first, then download files individually withgdown-O
Approach
1. Make the Drive folder public (anyone with link can view)
2. Use gdown Python package to download files
Setup
`bash
pip3 install gdown
`
Usage
`bash
Download entire folder (recursive)
gdown --folder "https://drive.google.com/drive/folders/FOLDER_ID?usp=sharing" -O /target/path/
Download specific file by ID
gdown "https://drive.google.com/file/d/FILE_ID/view?usp=sharing" -O /target/path/
Download with continue flag (resume interrupted)
gdown --continue --folder "https://drive.google.com/drive/folders/FOLDER_ID" -O /target/path/
`
Key insight
Making the folder public (via Drive sharing settings) is the simplest path when OAuth isn't available. The gdown package handles public folder access without any authentication — it just follows the share link.
gdown --json parsing pitfall
gdown --folder outputs a warning to stdout first:
`
WARNING: --json is in beta. Please report issues.
[{"path": "...", "url": "..."}]
`
The warning breaks JSON parsing if you pipe stdout directly to json.loads().
Correct parsing approach (Python):
`python
text = process.stdout
idx = text.find('[\n {') # Find where JSON actually starts
data = json.loads(text[idx:])
`
Wrong approach (returns empty or 0 items):
`python
lines = [l for l in text.split('\n') if l.startswith('[') or l.startswith('{')]
data = json.loads(lines[0]) # Gets only '[' character
`
Authentication expiry (critical)
Even "public" Drive folders can fail with:
`
Cannot retrieve the public link of the file. You may need to change the permission to 'Anyone with the link'
`
This happens when cookies/token used for listing expire. The listing endpoint is public, but the download URL requires a valid Google cookie session.
Symptoms:
Fix: Re-authenticate. Options:
1. Export fresh cookies from a logged-in browser session to /tmp/gdown_cookies.json
2. Use gdown --oauth to get a fresh OAuth token (requires browser confirmation)
3. Re-run rclone config to refresh Drive token
Cookie export format (/tmp/gdown_cookies.json):
`json
{"cookies": [{"domain": ".google.com", "name": "NID", "value": "..."}], "token": "..."}
`