Google Search Console API Setup
This guide walks you through setting up automated GSC data fetching.
Step 1: Enable the API
- Go to Google Cloud Console
- Create a new project or select existing one
- Go to APIs & Services → Library
- Search for “Google Search Console API”
- Click Enable
Step 2: Create Service Account (Recommended for Automation)
- Go to APIs & Services → Credentials
- Click Create Credentials → Service Account
- Name it
gsc-readeror similar - Click Create and Continue
- Skip role assignment (not needed for GSC)
- Click Done
- Click on the new service account
- Go to Keys tab → Add Key → Create new key
- Choose JSON and download
- Rename to
service_account.jsonand place inscripts/gsc/
Step 3: Grant Access in Search Console
- Go to Google Search Console
- Select your property (360tft.co.uk)
- Go to Settings → Users and permissions
- Click Add user
- Enter the service account email (from the JSON file, looks like
xxx@project.iam.gserviceaccount.com) - Set permission to Restricted (read-only)
- Click Add
Step 4: Add Secret to GitHub
- Go to your GitHub repo → Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
GSC_SERVICE_ACCOUNT - Value: Paste the entire contents of
service_account.json - Click Add secret
Step 5: Test Locally
cd scripts/gsc
pip install google-auth google-auth-oauthlib google-api-python-client
python fetch_gsc_data.py --days 7
How It Works
Automated (GitHub Actions)
- Runs every Monday at 8am UTC
- Fetches last 28 days of data
- Saves report to
scripts/gsc/data/gsc_latest.json - Creates GitHub issue with action items
Manual
# Last 28 days (default)
python fetch_gsc_data.py
# Last 90 days
python fetch_gsc_data.py --days 90
# Specific date range
python fetch_gsc_data.py --start 2025-01-01 --end 2025-01-31
Output
The script generates a JSON report with:
- action_items: Prioritized list of SEO tasks
- opportunities: Categorized findings
high_impression_low_ctr: Need better titles/descriptionsquick_wins: Position 11-20, can push to page 1ranking_opportunities: Position 5-20 worth optimizingtop_performers: Best performing queries
- raw_data: Top 100 query/page combinations
Claude Code Integration
When Claude Code reads scripts/gsc/data/gsc_latest.json, it will:
- Identify high-priority opportunities
- Suggest specific blog posts or page updates
- Recommend meta description improvements
- Track progress over time
Troubleshooting
“Permission denied” error
- Verify service account email is added to Search Console
- Check the property URL matches (sc-domain vs URL prefix)
“API not enabled” error
- Enable Search Console API in Google Cloud Console
No data returned
- GSC has a 3-day delay on data
- Verify you have data in Search Console web interface
- Check date range isn’t too recent
File Structure
scripts/gsc/
├── fetch_gsc_data.py # Main script
├── service_account.json # Credentials (DO NOT COMMIT)
├── SETUP.md # This file
└── data/
├── gsc_latest.json # Most recent report
└── gsc_report_*.json # Historical reports
Security Notes
service_account.jsonis in.gitignore- never commit credentials- GitHub secret stores credentials securely for Actions
- Service account has read-only access to GSC