Overview
The application authenticates with Google Drive using a service account, which:- Provides read-only access to shared Drive folders (
drive.readonlyscope) - Requires no user OAuth flow - authentication is automatic with the JSON key file
- Allows programmatic access to Drive content without browser interaction
- Must be granted access to the specific Drive folder containing course content
Prerequisites
- A Google account (personal or workspace)
- Access to Google Cloud Console
- A Google Drive folder containing your Platzi course content
Step 1: Create a Google Cloud Project
Navigate to Google Cloud Console
Go to Google Cloud Console and sign in with your Google account.
Create a new project
- Click on the project dropdown in the top navigation bar
- Click “New Project”
- Enter a project name (e.g., “Platzi Viewer”)
- Click “Create”
- Wait for the project to be created (this may take a few seconds)
Step 2: Enable the Google Drive API
Navigate to API Library
In the Google Cloud Console, go to “APIs & Services” → “Library” from the left sidebar menu.
You only need to enable the Drive API once per project. The API provides access to file metadata and content streaming.
Step 3: Create a Service Account
Navigate to Service Accounts
Go to “APIs & Services” → “Credentials” from the left sidebar, then click the “Credentials” tab.
Create service account
- Click ”+ CREATE CREDENTIALS” at the top
- Select “Service account” from the dropdown
Configure service account details
- Service account name: Enter a descriptive name (e.g., “platzi-viewer-service”)
- Service account ID: Auto-generated based on the name
- Description: Optional (e.g., “Read-only access to Platzi courses”)
- Click “Create and Continue”
Grant access (Optional)
You can skip the role assignment step by clicking “Continue” - we only need the service account key, not specific GCP roles.
Step 4: Generate Service Account Key
Find your service account
On the Credentials page, scroll down to the “Service Accounts” section. You should see your newly created service account listed.
Access Keys
- Click on the email address of your service account (e.g.,
[email protected]) - Go to the “Keys” tab
Step 5: Share Drive Folder with Service Account
The service account needs explicit permission to access your Drive folder.Copy service account email
Open your downloaded
service_account.json file and copy the client_email value.It looks like:Open Google Drive
Navigate to Google Drive and locate the folder containing your Platzi course content.
Share with service account
- Right-click on the folder
- Select “Share”
- Paste the service account email (from Step 1)
- Set permission to “Viewer” (read-only)
- Click “Send”
The Drive folder should be organized with this structure:See Building Cache for details on folder structure requirements.
Step 6: Configure Platzi Viewer
Place your service account key in the project directory:Verification
Test your service account configuration:test_drive_access.py
Replace
FOLDER_ID with your actual Google Drive folder ID. You can find this in the URL when viewing the folder in Drive:https://drive.google.com/drive/folders/17kPqqPSheDtQ5S1HM6Qvvh2qJ7O3YADmThe ID is the string after /folders/.Authentication Scopes
Platzi Viewer uses thedrive.readonly scope:
drive_service.py
- ✅ Read file metadata (name, size, MIME type)
- ✅ Download/stream file content
- ✅ List folder contents
- ❌ No write, delete, or modify permissions
- ❌ No access to files not explicitly shared with the service account
Troubleshooting
”Service account file not found”
Problem: Application cannot locateservice_account.json
Solution:
“Invalid grant: account not found”
Problem: Service account credentials are invalid or expired Solution:- Verify the JSON file is valid JSON (use
cat service_account.json | python -m json.tool) - Regenerate the service account key from Google Cloud Console
- Ensure you downloaded the correct key (not an OAuth client ID)
“User Rate Limit Exceeded”
Problem: Too many API requests in a short time Solution: The application includes automatic rate limiting and retry logic. If you still encounter this:- Wait a few minutes before retrying
- Check your Google Cloud Console quota usage
- Request quota increase if needed (rarely necessary)
rebuild_cache_drive.py script throttles requests to ~100 calls/second to stay within limits:
rebuild_cache_drive.py:26
“Folder not accessible”
Problem: Service account cannot access the Drive folder Solution:- Verify the folder is shared with the service account email
- Check the service account has “Viewer” or “Reader” permission
- Ensure the folder ID in your code/config is correct
- Test with a simple folder first before using production data
”Drive service not available (503)”
Problem: Application shows Drive unavailable in health check Solution:drive_service.py.
Next Steps
Build the Course Cache
With Drive access configured, scan your folder structure to generate the courses cache.Go to Building Cache →
Start Using Platzi Viewer
Complete the setup by starting the server and accessing the application.Go to Quickstart →