GA API Client
raw JSON → 0.6.6 verified Sat May 09 auth: no python
A Python client for the Google Analytics Data API v1 (beta). Version 0.6.6, released periodically.
pip install ga-api-client Common errors
error AttributeError: module 'ga_api_client' has no attribute 'GAAPIClient' ↓
cause Incorrect import path; `GAAPIClient` is not a direct attribute of the module if imported wrong.
fix
Use
from ga_api_client import GAAPIClient (note: import from the package name with underscores, not hyphens). error TypeError: __init__() got an unexpected keyword argument 'credentials' ↓
cause Breaking change in version 0.6.0 renamed the `credentials` parameter to `service_account_file`.
fix
Use
service_account_file or service_account_info instead of credentials. error google.api_core.exceptions.NotFound: 404 Request is missing required authentication credential ↓
cause Common when property_id is malformed (e.g., 'properties/123456789' instead of '123456789').
fix
Set property_id as a plain numeric string, e.g., '123456789'.
Warnings
breaking Version 0.6.0 removed the `credentials` parameter; use `service_account_file` or `service_account_info` instead. ↓
fix Replace `client = GAAPIClient(credentials=...)` with `client = GAAPIClient(service_account_file='path/to/key.json')`.
deprecated The `run_report` method's `dimension_filters` parameter is deprecated in favor of `dimension_filter` (singular). ↓
fix Use `dimension_filter` instead of `dimension_filters` in `run_report()`.
gotcha Property ID must be numeric (string of digits); passing a string with 'properties/' prefix or non-numeric values raises a misleading 404 error. ↓
fix Ensure `property_id` is a plain numeric string like '123456789'.
gotcha The client does not automatically refresh expired OAuth tokens; long-running applications may encounter token expiration errors. ↓
fix Reinitialize the client or implement a token refresh mechanism using google-auth's `RefreshToken`.
Imports
- GAAPIClient wrong
from ga_api_client.client import GAAPIClientcorrectfrom ga_api_client import GAAPIClient
Quickstart
from ga_api_client import GAAPIClient
import os
client = GAAPIClient(
property_id='123456789',
service_account_file=os.environ.get('GA_SERVICE_ACCOUNT_FILE', 'service-account.json')
)
response = client.run_report(metrics=['activeUsers'], date_ranges=['7daysAgo'])
print(response)