Reputation: 1
I've been trying to call the Analytics Data API using a service account for authentication.
To do so, I have
Unfortunately, whenever I try to run any Python scripts using the BetaAnalyticsDataClient, no matter which resource endpoint I try I end up getting this error
response = client.run_report(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/blah/newenv/lib/python3.11/site-packages/google/analytics/data_v1beta/services/beta_analytics_data/client.py", line 518, in run_report
response = rpc(
^^^^
File "/blah/newenv/lib/python3.11/site-packages/google/api_core/gapic_v1/method.py", line 113, in __call__
return wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/blah/newenv/lib/python3.11/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/blah/newenv/lib/python3.11/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded
I've even tried https://github.com/googleapis/python-analytics-data/blob/main/samples/snippets/get_common_metadata.py which uses some global internal property, but still get a DeadlineExceeded error.
I've also tried BetaAnalyticsDataClient.from_service_account_file("the_file") when initializing the client in hopes this would work.
Additionally as a test - although I have no clue if this should even work - have tried:
curl -X GET \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
https://analyticsdata.googleapis.com/v1beta/properties/0/metadata
which returns
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
"domain": "googleapis.com",
"metadata": {
"method": "google.analytics.data.v1beta.BetaAnalyticsData.GetMetadata",
"service": "analyticsdata.googleapis.com"
}
}
]
}
}
and have tried this on the property which I gave the service account administrator access.
Is there something else I need to enable for service accounts to work?
Upvotes: 0
Views: 1845
Reputation: 117301
Its hard to help without seeing your code but the error message is telling you what the issue is Request had insufficient authentication scopes.
When making a request you need to be authorized with one of the following scopes.
Fix your scope and try again.
Upvotes: 0