Gmail OAuth Setup
Set up Gmail API access via gog CLI with manual OAuth flow. Use when setting up Gmail integration, renewing expired OAuth tokens, or troubleshooting Gmail authentication on headless servers.
Set up Gmail API access via gog CLI with manual OAuth flow. Use when setting up Gmail integration, renewing expired OAuth tokens, or troubleshooting Gmail authentication on headless servers.
Real data. Real impact.
Emerging
Developers
Per week
Open source
Skills give you superpowers. Install in 30 seconds.
Headless-friendly OAuth flow for Gmail API access using
gog CLI.
gog CLI installed (brew install steipete/tap/gogcli)gmail.modify (or others as needed)gog auth credentials /path/to/client_secret.json gog auth keyring file # Use file-based keyring for headless export GOG_KEYRING_PASSWORD="your-password" # Add to .bashrc
Run
scripts/gmail-auth.sh interactively, or:
# Generate URL scripts/gmail-auth.sh --urlUser opens URL, approves, copies code from localhost redirect
Exchange code (do this quickly - codes expire in minutes!)
scripts/gmail-auth.sh --exchange CODE EMAIL
gog gmail search 'is:unread' --max 5 --account you@gmail.com
Cause: App is in "Testing" mode and the Gmail account isn't a test user.
Solutions (choose one):
Publish the app (recommended):
Add test user:
This is normal for personal apps. Click:
Safe to proceed since you own the app.
Cause: App is in "Testing" mode.
Fix: Publish the app (see above). Published apps get permanent refresh tokens.
Causes:
Fix: Generate a fresh auth URL and complete the flow quickly. Paste the code immediately after getting it.
Cause: The redirect URI in the token exchange doesn't match what was used in the auth URL.
Fix: This script uses
http://localhost. Make sure both the auth URL and exchange use the same redirect URI.
Cause: Browser trying to connect to localhost which doesn't exist on phone.
Fix:
http://localhost/?code=4/0ABC...Cause: Too many OAuth scopes requested.
Fix: Use minimal scopes.
gmail.modify alone is usually sufficient and shows just one permission.
Cause: Signed into wrong Google account.
Fix: Check which account owns the project:
Cause: Google deprecated
urn:ietf:wg:oauth:2.0:oob for OAuth clients created after 2022.
Fix: Use
http://localhost redirect instead (this script's default). After approval, browser redirects to localhost with code in URL.
| Scope | Access |
|---|---|
| Read, send, delete, manage labels (recommended) |
| Read only |
| Send only |
| Create drafts, send |
scripts/gmail-auth.sh — Interactive auth helpergmail.modify covers most use casesNo automatic installation available. Please visit the source repository for installation instructions.
View Installation Instructions1,500+ AI skills, agents & workflows. Install in 30 seconds. Part of the Torly.ai family.
© 2026 Torly.ai. All rights reserved.