I have just verified, that the service-account has access to GA4 via Cloud Shell like so:
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import RunReportRequest, DateRange, Metric, Dimension
client = BetaAnalyticsDataClient.from_service_account_file("key.json")
property_id = "YOUR-GA4-PROPERTY-ID"
request = RunReportRequest(
property=f"properties/{property_id}",
dimensions=[Dimension(name="country")],
metrics=[Metric(name="activeUsers")],
date_ranges=[DateRange(start_date="7daysAgo", end_date="today")],
)
try:
response = client.run_report(request)
print("✅ Success! You have access.")
for row in response.rows:
print(row)
except Exception as e:
print("❌ Failed. Error was:")
print(e)
which ran successfully. I am also seeing the expected Dataset in BQ but its just empty.