Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Understanding the permission error in Google Analytics Admin API. › Reply To: Understanding the permission error in Google Analytics Admin API.
-
The
PermissionDenied: 403 The caller does not have permission error
occurs because the service account you’re using doesn’t have the necessary permissions. This error can occur even if you’ve assigned full owner permissions to the service account. The Google Analytics API relies on a different set of permissions which need to be assigned within the Google Analytics Admin Console.You need to add the service account email to the user management section in the Admin Console of the Analytics account you are trying to access. In that User Management, you’ll want to ensure you’ve provided ‘Read & Analyze’ access at a minimum and if you need to manage other aspects of the account, you may need additional permissions.
The blank list results from
client.list_accounts()
also suggests that the service account doesn’t have permission to view any accounts.Please note that each of your Google Analytics accounts (UA or GA4) will have to be individually shared with the service account’s email for it to be able to access them via the API.
And please ensure you have the latest Google analytics libraries installed properly. If you have previous versions you might run into compatibility issues which can cause permission issues as well.
As you’ve mentioned you’ve multiple Google Analytics account under same google account, make sure you are trying to get data for the accounts for which your service account has proper permissions. Check that the service account key you are using is for the same project in which the Google Analytics API is enabled.