Search code examples
google-cloud-platformgoogle-analyticsgoogle-analytics-apigoogle-analytics-4

Google Analytics v4 API Error: "User does not have sufficient permissions for this profile."


I'm trying to access Google Analytics v4 API using Python and got this error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "User does not have sufficient permissions for this profile.". Details: "User does not have sufficient permissions for this profile.">

I am using a Service Account

How I created the service account?

  • Went into Google Cloud Console.
  • Created a new project dedicated only to this API.
  • Enabled the Analytics Reporting API, Google Analytics Admin API, Google Analytics Data API and Google Analytics API.
  • Went into Credentials and created a new service account.
  • Gave it the appropriate credentials.
  • Added the scopes into Domain-wide Delegation.
  • Added the service account email ([email protected]) to Google Analytics dashboard as an admin.

How I tried to fix it so far?

  • Added the service account user email as Analytics Dashboard admin.
  • Added the scopes to Domain-wide Delegation in Google Cloud.
  • Read Google's documentation.
  • Changed to a different Service Account .json file who also has the credentials, yet couldn't get that to work.
  • Followed this tutorial (by Google) but yet - it's not working.
  • Changed to another VIEW_ID - yet not working.

Google's API says that the service do initialize, but cannot get data - get 403.

I've read all questions and answer in Stackoverflow, but yet couldn't find a sufficient solution that solves this problem.


Solution

  • After posting the question, I kept looking and searching the web and I found out that most of the questions and tutorials are not up-to-date because Google is constantly updating the API's. I found out that this documentation is referring to Universal Analytics v4 (which is deprecated and no logger supported).

    So if you want to make requests to Google Analytics API, and you are using GA4 (which probably you do), you should enable Google Analytics Data API (GA4) in Google Cloud Console and follow this documentation.

    After doing that I was able to access the API and get the data I was looking for.

    Good luck everyone!