This guide walks you through setting up Google Calendar API credentials for the to-do agent.
- Google account
- Python environment with dependencies installed
- Go to Google Cloud Console
- Click "Select a project" → "New Project"
- Enter project name:
todo-agent(or your preferred name) - Click "Create"
- In your project dashboard, click "APIs & Services" → "Library"
- Search for "Google Calendar API"
- Click on "Google Calendar API"
- Click "Enable"
-
Go to "APIs & Services" → "Credentials"
-
Click "Create Credentials" → "OAuth client ID"
-
If prompted, configure OAuth consent screen:
- User Type: External
- App name:
To-Do Agent - User support email: Your email
- Developer contact: Your email
- Click "Save and Continue"
- Scopes: Skip (click "Save and Continue")
- Test users: Add your email
- Click "Save and Continue"
-
Create OAuth Client ID:
- Application type: Desktop app
- Name:
To-Do Agent Desktop - Click "Create"
-
Download credentials:
- Click the download icon (⬇️) next to your newly created OAuth client
- Save the file as
credentials.jsonin your project root directory
Your project should now have:
my-agent/
├── credentials.json # ← Download from Google Cloud Console
├── .env # Your environment variables
├── app.py
├── requirements.txt
└── ...
IMPORTANT:
credentials.jsonis in.gitignore- NEVER commit this file!token.jsonwill be auto-generated on first run - also in.gitignore
When you first run a task with a due date, the agent will:
- Open your default web browser
- Ask you to sign in to your Google account
- Request permission to access your Google Calendar
- Click "Allow"
- Browser will show "Authentication successful" - you can close it
The agent will save the token to token.json for future use.
Try these commands with the agent:
python app.pyYou: remind me to call Gabi tomorrow at 10am
🤖 Agent: I've added "call Gabi" to your task list and created a calendar reminder for tomorrow at 10:00 AM!
Check your Google Calendar - you should see the event!
- Make sure you downloaded the credentials file from Google Cloud Console
- Rename it to exactly
credentials.json - Place it in the project root directory (same level as
app.py)
- In Google Cloud Console, make sure your app is in "Testing" mode
- Add your email to "Test users" in the OAuth consent screen
- Delete
token.jsonand re-run the authentication flow - Make sure you granted all requested permissions
- Google Calendar API has a quota of 1,000,000 queries/day
- For a personal to-do agent, you'll never hit this limit
- In production, implement exponential backoff for rate limit errors
✅ DO:
- Keep
credentials.jsonandtoken.jsonin.gitignore - Use environment variables for sensitive config
- Only grant minimum required scopes (
calendar.events) - Regularly review authorized apps in your Google Account settings
❌ DON'T:
- Commit credentials to git (even private repos)
- Share credentials with others
- Use production credentials for development
- Grant full calendar access if you only need events
For production use (e.g., deployed as a service):
-
Service Account Auth (instead of OAuth)
- Create a service account in Google Cloud Console
- Download service account key JSON
- Use
google.oauth2.service_account.Credentials - No browser-based OAuth flow needed
-
Secret Management
- Use cloud secret managers (AWS Secrets Manager, Google Secret Manager)
- Never store credentials in code or environment variables in cloud platforms
- Rotate credentials regularly
-
Scope Down Permissions
- Use
calendar.events.readonlyif only reading - Use specific calendar IDs instead of 'primary'
- Implement least-privilege access
- Use
When discussing this integration:
-
OAuth 2.0 Flow: "I implemented the authorization code flow for desktop apps, which opens a browser for first-time auth and uses refresh tokens for subsequent access."
-
Security: "Credentials are gitignored and tokens are stored locally. In production, I'd use a service account with secret management."
-
Error Handling: "The code handles token expiration with automatic refresh, and gracefully fails if the API is unavailable."
-
Scope Limitation: "I only request
calendar.eventsscope, not full calendar access - principle of least privilege." -
Rate Limiting: "Google Calendar has generous quotas, but I'd implement exponential backoff and circuit breakers for production."
-
Testing Strategy: "For testing, I'd use the Google Calendar API test environment and mock the API calls in unit tests."
Happy Scheduling! 📅