name: doccorretor-google-drive-migration
description: Migrate documents from Google Drive to DocCorretor — OAuth setup, rclone config, and migration strategies
tags:
- google-drive
- doccorretor
- migration
- oauth
DocCorretor Google Drive Migration
Context
DocCorretor (documentos.rochasalesseguros.com.br) needs to migrate documents from Google Drive. The Drive folder contains documents organized by month and client name (uppercase). The DocCorretor app uses the same Google OAuth app (GOOGLE_CLIENT_ID_REDACTED) already configured in its .env.
Google OAuth Setup (One-Time)
Step 1: Get authorization code
User opens this URL (while logged into the Drive account):
`
https://accounts.google.com/o/oauth2/v2/auth?client_id=GOOGLE_CLIENT_ID_REDACTED&response_type=code&scope=https://www.googleapis.com/auth/drive.readonly&redirect_uri=http://localhost:1/callback&access_type=offline&prompt=consent
`
After accepting, the page will show "redirect_uri não encontrado" — copy the code= parameter from the URL.
Step 2: Exchange code for tokens
`bash
curl -s -X POST https://oauth2.googleapis.com/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=GOOGLE_CLIENT_ID_REDACTED" \
-d "client_secret=GOOGLE_CLIENT_SECRET_REDACTED" \
-d "code=USER_CODE_HERE" \
-d "redirect_uri=http://localhost:1/callback" \
-d "grant_type=authorization_code"
`
Returns: access_token, refresh_token, expires_in
Step 3: Save token and use with rclone or Drive API
`python
import json
token = {"access_token": "REDACTED", "refresh_token": "...", "expiry": ...}
with open('/tmp/gdrive_token.json', 'w') as f:
json.dump(token, f)
`
rclone Configuration (Post-Auth)
`ini
[gdrive]
type = drive
scope = drive.readonly
token = {"access_token":"...","refresh_token":"...","token_type":"Bearer","expiry":"..."}
`
Then list with:
`bash
rclone lsjson --config /tmp/rclone-gdrive.conf --drive-root-folder-id FOLDER_ID --recurse gdrive:/
`
Key Files
- - OAuth Client ID:
GOOGLE_CLIENT_ID_REDACTED - - OAuth Client Secret:
GOOGLE_CLIENT_SECRET_REDACTED(from VPS:/var/www/documentos2/app/.env) - - Drive Folder ID:
1zVhApvpFM937qxsvsz37WCcUD-7f2zUP - - Google Drive API requires OAuth — API key alone (even with folder shared) returns 403
- - gdown can download files but cannot list directories
- - Browser tool (playwright) needs display server — fails in headless VPS environment
- - OAuth refresh token never expires unless revoked
Known Limitations
Migration Options
1. Automatic: Script parses filenames, matches to existing clients, creates folder structure
2. Review mode: List all files first, present plan for user approval before importing
3. Manual selective: User picks which folders/files to import one by one