Overview
This guide walks you through setting up Google Drive API access from creating a project to getting a long-lived refresh token. It uses the Desktop app OAuth flow which works reliably for scripts.Important: Keep the app in Testing mode (no verification needed, but limited to test users). Always add your own email as a test user early to avoid “Access blocked: app not verified” errors.
Step 1: Create a Google Cloud Project
Open Google Cloud Console
Create new project
- Click the project dropdown in the top bar
- Click New Project
- Name it (e.g.,
gdrive-ingest-script) - Click Create and wait a few seconds
Step 2: Enable the Google Drive API
Step 3: Create OAuth Consent Screen
Add scopes
- Click Add or remove scopes
- Search for drive
- Check
.../auth/drive(full access) - Click Update
- Click Save and Continue
Add test users (CRITICAL)
- Click + Add users
- Enter your email address (the one you’ll use to sign in)
- Click Add
- Click Save and Continue
This prevents “Access blocked: app not verified” errors during authorization.
Step 4: Create Desktop OAuth Credentials
Step 5: Get the Refresh Token
Method 1: Manual Code Flow (Recommended)
Authorize and get code
- Open the URL in your browser
- Sign in with the test user email you added in Step 3
- Consent screen appears → Click Allow
- Google shows a verification code on the page (long string like
4/0AX4...) - Copy the code
Exchange code for refresh token
Run this curl command (replace placeholders):You’ll get JSON response:
Method 2: OAuth Playground (Alternative)
Using Google OAuth Playground
Using Google OAuth Playground
Open OAuth Playground
Configure with your credentials
- Click settings (gear icon) in top right
- Check “Use your own OAuth credentials”
- Enter your
CLIENT_IDandCLIENT_SECRET
Select scopes
- In Step 1, find “Drive API v3”
- Select
https://www.googleapis.com/auth/drive - Click “Authorize APIs”
This method is easier but gives full drive scope access.
Step 6: Configure the Script
Step 7: Test the Script
- Refreshes token automatically if needed
- Shows folder list
- Lets you pick destination
- Downloads, organizes, and uploads
Troubleshooting
Access blocked: app not verified
Access blocked: app not verified
Cause: Your email is not added as a test user.Solution:
- Go to OAuth consent screen in Google Cloud Console
- Click Test users → + Add users
- Add your email address
- Wait 1-5 minutes and retry authorization
unauthorized_client or Unauthorized
unauthorized_client or Unauthorized
redirect_uri_mismatch
redirect_uri_mismatch
Cause: Wrong redirect URI in authorization URL.Solution:
Make sure you’re using
urn:ietf:wg:oauth:2.0:oob in the auth URL.403 access_denied
403 access_denied
Cause: You’re not a test user.Solution:
Add yourself again in OAuth consent screen → Test users.
Token expires quickly
Token expires quickly
This is normal!
- Access token lasts ~1 hour
- Script auto-refreshes using the long-lived refresh token
- Refresh token remains valid indefinitely (until revoked)
Refresh token stops working
Refresh token stops working
Possible causes:
- Client secret was reset
- Token was manually revoked
- App was removed from authorized apps
Security Notes
Best practices:Use .env file
Store credentials in
.env (already in .gitignore)Dedicated account
Consider using a dedicated Google account (not your personal one)
Rotate credentials
Reset client secret periodically if you’re security-conscious
Restrict permissions
Token Lifecycle
Key points:- Access token: Short-lived (~1 hour), used for API calls
- Refresh token: Long-lived (years), used to get new access tokens
- Script automatically refreshes access tokens as needed
- You only need to do the OAuth flow once
Next Steps
Setup Guide
Complete the script setup
Usage Examples
Start uploading files
Telegram Integration
Optional: Enable Telegram downloads
Troubleshooting
Fix common issues