What you’ll learn: How to set up Google Ads API access, authenticate with OAuth 2.0, pull campaign data programmatically, and feed it to AI models for analysis. Includes working code you can run today.
An API (Application Programming Interface) is how software talks to other software. When you log into Google Ads and click “Download Report,” you are using a graphical interface. When your script calls the Google Ads API to pull the same report, it gets the same data—but can then immediately send that data to Claude for analysis, generate recommendations, and push changes back to the platform. No manual steps, no copy-pasting CSVs, no delays.
When I managed 200+ campaigns at NortonLifeLock, manually reviewing search query reports across every campaign would take 3-4 hours per week. An API-connected script does the same analysis in under 3 minutes. Over a year, that is 200 hours reclaimed—time I spent on strategy, creative testing, and the work that actually moved performance. Search Engine Land’s 2026 PPC trends panel confirmed this: the best performers embraced automation without surrendering strategic control.
# 1. Log into your Google Ads MCC (Manager Account)
# 2. Navigate to: Tools & Settings > Setup > API Center
# 3. If you don't see API Center, you need an MCC account
# Create one at: https://ads.google.com/home/tools/manager-accounts/
# 4. Apply for API access (Basic access is sufficient to start)
# 5. Your developer token will be displayed in API Center
# Store it:
export GOOGLE_ADS_DEVELOPER_TOKEN='your-developer-token'
# 1. Go to: https://console.cloud.google.com
# 2. Create a new project (or select existing)
# 3. Enable the Google Ads API:
# APIs & Services > Library > Search 'Google Ads API' > Enable
# 4. Create OAuth credentials:
# APIs & Services > Credentials > Create Credentials > OAuth 2.0
# 5. Application type: Desktop app
# 6. Download the JSON file
# Install the Google Ads Python library:
pip install google-ads
# Generate refresh token:
python -m google_ads.generate_refresh_token \
--client_id YOUR_CLIENT_ID \
--client_secret YOUR_CLIENT_SECRET
Create a file called google-ads.yaml in your home directory:
# ~/google-ads.yaml
developer_token: 'YOUR_DEVELOPER_TOKEN'
client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com'
client_secret: 'YOUR_CLIENT_SECRET'
refresh_token: 'YOUR_REFRESH_TOKEN'
login_customer_id: '1234567890' # Your MCC ID, no dashes
use_proto_plus: true
Here is a complete script that pulls your campaign performance data via the Google Ads API and sends it to Claude for analysis:
from google.ads.googleads.client import GoogleAdsClient
import anthropic
# Initialize clients
gads = GoogleAdsClient.load_from_storage('google-ads.yaml')
claude = anthropic.Anthropic()
# Pull last 30 days of campaign data
query = '''
SELECT
campaign.name,
metrics.cost_micros,
metrics.conversions,
metrics.clicks,
metrics.impressions,
metrics.cost_per_conversion
FROM campaign
WHERE segments.date DURING LAST_30_DAYS
AND campaign.status = 'ENABLED'
ORDER BY metrics.cost_micros DESC
'''
customer_id = '1234567890' # Your account ID
service = gads.get_service('GoogleAdsService')
response = service.search(customer_id=customer_id, query=query)
# Format data for AI analysis
data = 'Campaign | Cost | Conversions | CPA\n'
for row in response:
cost = row.metrics.cost_micros / 1_000_000
data += (f'{row.campaign.name} | ${cost:.2f} | '
f'{row.metrics.conversions:.0f} | '
f'${row.metrics.cost_per_conversion:.2f}\n')
# Send to Claude for analysis
analysis = claude.messages.create(
model='claude-sonnet-4-20250514',
max_tokens=2000,
messages=[{
'role': 'user',
'content': f'''Analyze this Google Ads campaign data.
Identify: top 3 optimization opportunities, any campaigns
that should be paused, and budget reallocation suggestions.
{data}'''
}]
)
print(analysis.content[0].text)
The script above is a simplified version of what GoogleAdsAgent.ai’s Campaign Intelligence sub-agent runs continuously. The production version includes error handling, rate limit management, historical trend analysis, and automated action execution. But the core pattern is identical: pull data from Google Ads API, analyze with AI, take action.
📦 GitHub: https://github.com/itallstartedwithaidea/google-ads-api-agent — The full Python agent with 28 automation actions, OAuth setup, and production error handling
📦 GitHub: https://github.com/itallstartedwithaidea/google_ads_anomoly_detection_script — Google Ads Script for real-time anomaly detection—alerts you when metrics deviate from expected ranges
Website: https://googleadsagent.ai | GitHub: https://github.com/itallstartedwithaidea | Tools: https://googleadsagent.ai/tools
About the Author
John Williams is a Senior Paid Media Specialist at Seer Interactive with 15+ years managing $48M+ in digital ad spend across Google, Microsoft, Meta, and Amazon. Founder of It All Started With A Idea and creator of GoogleAdsAgent.ai. Speaker at Hero Conf on AI in advertising. Former WSU football player and current assistant football coach at Casteel High School, AZ.
Get a free 30-day audit of your advertising accounts. John will personally review your setup and provide actionable recommendations.
John will review your account and reach out within 24 hours.