Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics API: "User does not have sufficient permissions for this account."

I'm writing a Ruby app that accesses the Google Analytics API to pull down some experiment information.

The app connects and authenticates using a Google Service Account via the following function:

def connect   ...   @@client = Google::APIClient.new(:application_name => 'My Service App',                                      :application_version => '1.0.0')   key_file = Rails.root.join('config', 'privatekey.p12').to_s   key_secret = 'somesecret'   key = Google::APIClient::PKCS12.load_key(key_file, key_secret)   asserter = Google::APIClient::JWTAsserter.new(     SECRETS[:google_service_account_email],     ['https://www.googleapis.com/auth/yt-analytics.readonly',      'https://www.googleapis.com/auth/analytics.readonly'     ],     key   )   @@client.authorization = asserter.authorize()   ... end 

...which authenticates and discovers both APIs without issue.

Using the client against the YouTube Analytics API works without issue. Using the same exact account to access the Analytics API via...

response = @@client.execute({   # 'analytics is the API object retrieved via discover_api()   :api_method => analytics.management.experiments.list,    :parameters => {     'accountId' => 'AAAAAAAA',     'profileId' => 'PPPPPPPP',     'webPropertyId' => 'UA-WWWWWWWW-#'   } }) 

Results in a 403 error response:

{"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this account."} 

In regards to authorization, I have double-checked the account [email protected]:

  • Has full permissions to the Google Analytics web interface. I logged in using the [email protected] account and was able to view the same Experiments I attempted to list.
  • Has enabled the Analytics API. Within the API Console, I confirmed in the Services section that the Analytics API item is switch to ON. (Just like YouTube Analytics is.)
  • I am using the appropriate AccountID, ProfileID, and WebPropertyID values. Copied directly from the Google Analytics web interface.

Given that the service account can access at least one API (YouTube Analytics), and the associated account ([email protected]) can access the Analytics web interface, there seems to be something wrong with the service account accessing the Analytics API in particular.

Any ideas?

Similar topics:

  • “Not sufficient permissions” google analytics API service account (NOTE: This error is slightly different than mine)
  • Analytics blog post, check comments section for 'permissions'
like image 493
David Elner Avatar asked Jan 06 '14 21:01

David Elner


People also ask

How do I give permission to Google Analytics?

Sign in to Google Analytics. Click Admin, and navigate to the desired account/property/view. In the Account, Property, or View column (depending upon whether you want to add users at the account, property, or view level), click Access Management. In the Account permissions list, click +, then click Add users.

How do I check permissions in Google Analytics?

To get started, you'll need to sign into your Google Analytics account. Then, click the Admin option at the bottom of your Analytics panel on the left. Now, you'll see the 3 levels of access (i.e. Account, Property, and View). And, you'll also find the User Management option below all 3 access levels.

Why does Google Analytics say Permission denied?

Longer answer/explanation — Apparently this error seems to be caused by a bug in Google Analytics website (as of Nov 2020) which occurs whenever you are logged in to Google Analytics with a different Google account than the default, first account, and the default account not having access to your Google Analytics ...

Does Google Analytics have an API?

The Google Analytics Reporting API v4 provides programmatic methods to access report data in Google Analytics (Universal Analytics properties only). With the Google Analytics Reporting API, you can: Build custom dashboards to display Google Analytics data. Automate complex reporting tasks to save time.


1 Answers

Make sure you give the service account email (something like [email protected]) permissions to read/write from your GA view.

Admin > View > User Management > "Add permissions for:"

like image 119
Goose Avatar answered Sep 23 '22 17:09

Goose