Analytics Google API Error 403: “User does not hav

2019-01-04 21:58发布

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.

11条回答
甜甜的少女心
2楼-- · 2019-01-04 22:02

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

查看更多
做自己的国王
3楼-- · 2019-01-04 22:04

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!

查看更多
Root(大扎)
4楼-- · 2019-01-04 22:08

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 1234567890@developer.gserviceaccount.com) 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!

查看更多
叛逆
5楼-- · 2019-01-04 22:11

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

查看更多
不美不萌又怎样
6楼-- · 2019-01-04 22:13

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":"me.example@gmail.com"
  "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 (me.example@gmail.com).

查看更多
女痞
7楼-- · 2019-01-04 22:14

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.

查看更多
登录 后发表回答