Google Docs Skill
by @zagran
Integrate with Google Docs API to create, read, update, format, and manage documents using OAuth 2.0 authentication.
import urllib.request
import json
import osGet access token first (using function from above)
access_token = get_access_token()Get document
req = urllib.request.Request('https://docs.googleapis.com/v1/documents/{documentId}')
req.add_header('Authorization', f'Bearer {access_token}')
doc = json.load(urllib.request.urlopen(req))
print(json.dumps(doc, indent=2))
1. Google Cloud Project Setup - Go to Google Cloud Console - Create a new project or select existing one - Enable the Google Docs API - Create OAuth 2.0 credentials (Desktop app or Web application) - Download the credentials JSON file
2. Environment Setup
export GOOGLE_CLIENT_ID="your-client-id"
export GOOGLE_CLIENT_SECRET="your-client-secret"
export GOOGLE_REFRESH_TOKEN="your-refresh-token"
1. Token Management - Cache access tokens (valid for 1 hour) - Store refresh token securely - Implement automatic token refresh
2. Batch Operations - Combine multiple updates into single batch call - Reduces API calls and improves performance
3. Index Calculation
- Always get current document state before updates
- Account for newline characters (\n)
- Use endOfSegmentLocation for appending
4. Rate Limits - Google Docs API has quotas (check Cloud Console) - Implement exponential backoff for rate limit errors
clawhub install google-docs-skill