Analytics Google API Error 403: "User does not have any Google Analytics Account"

Error HandlingGoogle Analytics

Error Handling Problem Overview


I'm creating an script, based on Google Analytics step-by-step guide from this page:

> https://developers.google.com/analytics/resources/tutorials/hello-analytics-api

Authorization is done without problems, until it tries to access data. The return code is 403, and error message is:

> User does not have any Google Analytics account

This message has no sense: my account has google analytics data, tracking multiple websites, and I can access it from web browser without problem. I've allowed Analytics API through Google APIs console, and API access is giving me right data.

Error Handling Solutions


Solution 1 - Error Handling

I had this problem too. I fixed it by adding the email address for my service account to the Google Analytics profile I wanted it to access.

I got the email address (something like [email protected]) for the service account by looking under the "API Access" tab in the Google APIs console.

Then, I followed Google's instructions for adding an email address to an Analytics profile. Now everything's working as expected.

Good luck!

Solution 2 - Error Handling

Just add you given email (format of 71667655853644-o653rrdkq5hthsgo0otbpojoo@developer.gserviceaccount.com)

to User Managers:

User does not have any Google Analytics account

Wish it helps you

Solution 3 - Error Handling

I was facing the same issue. It got resolved by adding the email id of the service account user(your [email protected]), to the users in your Analytics account under-

Analytics-Home Page ->Admin(left pane) -> User Management -> add (click on plus sign on right side of the menu) -> Add new User -> Add the email id in enter email addresses.

enter image description here

Now, this will solve the issue.

Solution 4 - Error Handling

It is mentioned in a comment above but if you add the email address under the User Management for your account, it won't work. You have to click on the User Management under the view part of the screen.

enter image description here

Solution 5 - Error Handling

This message we get when no permission granted to client_email, in the google alalytics, client_email is you got from the JSON file. to grant permission to client_email you're using in your App, Head over to Google Analytics site and click "Admin (setting icon)"

enter image description here

you'll get menu list right, there click on "View User Management"

enter image description here

There you'll see "+" icon, and "add user",

enter image description here

once you click on that, you need to add client_email in the "email address field" and save it, you should be good to go!

enter image description here

Solution 6 - Error Handling

Go to https://console.cloud.google.com/apis/credentials

Copy email address in "Service Account".

enter image description here

Open Google Analytics, add email above as a new user.

Solution 7 - Error Handling

You will also get this error if you have never logged in with the google account youre trying to authenticate with.

Solution 8 - Error Handling

I was getting the 403 error until I changed the permissions of the email account from inside Google Analytics from 'Read & Analyze' to something else, saved it, and then changed the permissions back to 'Read & Analyze' and it worked.

Solution 9 - Error Handling

Just in case if that doesn't work, Try to open your JSON file which you have downloaded and Search for client_email and copy that email address and add it to the View File

Click On

Analytics-Home Page ->Admin(left pane) -> User Management -> add (click on plus sign on right side of the menu) -> Add new User -> Add the client_email address which you copied.

If that still doesn't work

Analytics-Homepage-> Admin ->Views->User Management(Click on add(+) symbol, add this ccopied client_email address and give permissions and save it.

Solution 10 - Error Handling

I was hitting the 403 error. These steps got me around it. To be clear, I was trying to get Google's sample "HelloAnalytics.php" working with OAuth (sans user interaction, suitable for cron job etc).

After enabling the Analytics API, I created a new "Service Account" under APIs & Auth/Credentials; and saved the .p12 key pair. I then went into the Analytics user management console, and added that Service User's email address.

.p12 authorization using the PHP API works if I check off only "Read & Analyze" only in the permissions list. If I add "Manage Users" and/or "Edit", I get the 403. Hope this is helpful, I was grinding on this for a couple of hours...

Solution 11 - Error Handling

I had this problem too, and I found that the problem was that I had asked for too many permissions. The Developer Console says to ask for both http://www.googleapis.com/auth/analytics and http://www.googleapis.com/auth/analytics.readonly permissions. This did not work when I was also using the sub claim. A sub claim instructs Google to issue an access token that operates on behalf of another user — in my case the Google account that owns the service account. I removed the analytics permission and stuck with analytics.readonly with the sub claim:

{
  "iss":"123123123123123-xxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com",
  "sub":"[email protected]"
  "scope":"http://www.googleapis.com/auth/analytics",
  ...
}

The Bearer token issued allows me to make (at least some) Google Analytics queries to profiles that are owned by completely different Google accounts, but that have been shared (read-only) with my gmail user ([email protected]).

Solution 12 - Error Handling

I managed to fix this by making sure that the

client = Google::APIClient.new(:application_name => 'X',:application_version => '1')

application name variable 'X above was the ACCOUNT name on the GA dashboard, not the PROPERTY name, which in my case was the actual url of the site I want to access.

Confusing, but thankfully fixed (with no thanks to Google!)

Solution 13 - Error Handling

The problem happens since we dont provide a "sub" argument. Unless we provide this, the call happens on behalf of that long service account email.

So just provide a sub argument, with an email which you already have given access in the report and things should work well!

Solution 14 - Error Handling

I got the same error, since I didn't sign in the google analytics. So I had resolved it by signing in the analytics account.

Solution 15 - Error Handling

Instead of using a service account, you can sidestep the need for adding a adding new user permissions (as per the top answers in this thread) by using OAuth client ID credentials.

Go to the API credentials dashboard and click "Create credentials" -> "OAuth client ID". Afterwards you should get a client ID and a client secret that you'll need to authenticate the API.

Now you can use OAuth2WebServerFlow to authenticate on a per-use basis. Here is a python3 example:

from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow

# TODO: Fill these in...
CLIENT_ID = ''
CLIENT_SECRET = ''
VIEW_ID = ''

flow = OAuth2WebServerFlow(
    CLIENT_ID, CLIENT_SECRET,
    'https://www.googleapis.com/auth/analytics.readonly',
    redirect_uri='urn:ietf:wg:oauth:2.0:oob'
)

authorize_url = flow.step1_get_authorize_url()
print('Receive code from:\n%s\n' % authorize_url)
code = input('Enter code here:').strip()
credentials = flow.step2_exchange(code)
    
api = build('analyticsreporting', 'v4', credentials=credentials)
body={
    'reportRequests': [{
        'viewId': VIEW_ID,
        'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
        'metrics': [{'expression': 'ga:sessions'}],
        'dimensions': [{'name': 'ga:country'}]
    }]
}

data = api.reports().batchGet(body=body).execute()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser989501View Question on Stackoverflow
Solution 1 - Error HandlingS MView Answer on Stackoverflow
Solution 2 - Error HandlingitsnikolayView Answer on Stackoverflow
Solution 3 - Error Handlingvikash singhView Answer on Stackoverflow
Solution 4 - Error HandlingLukosView Answer on Stackoverflow
Solution 5 - Error HandlingEricgitView Answer on Stackoverflow
Solution 6 - Error Handlingsearching9xView Answer on Stackoverflow
Solution 7 - Error HandlingAndrew BullockView Answer on Stackoverflow
Solution 8 - Error HandlingPearceView Answer on Stackoverflow
Solution 9 - Error HandlingBits PleaseView Answer on Stackoverflow
Solution 10 - Error HandlingJohnny OView Answer on Stackoverflow
Solution 11 - Error HandlingmogsieView Answer on Stackoverflow
Solution 12 - Error HandlingJonathan_WView Answer on Stackoverflow
Solution 13 - Error HandlingSony KadavanView Answer on Stackoverflow
Solution 14 - Error HandlingRumman SiddiquiView Answer on Stackoverflow
Solution 15 - Error HandlingAlexView Answer on Stackoverflow