0
votes

Ok So as the title suggest Google Analytics API Problems...

Now before i start and some one pipes up Duplicate.... i have read though

403 Insufficient permissions error while trying to get Google Analytics data

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

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

And still unable to get it to work. I have the scope added like so:

$client->addScope("https://www.googleapis.com/auth/analytics");

As it stands i have the view id (profile) i'm trying to query:46034120 So i get the service

$this->service = new \Google_Service_Analytics($client);

and i call:

$this->service->data_ga->get(
    'ga:46034120',
    '7daysAgo',
    'today',
    'ga:session');

As for the questions at the start i have made sure that this view can be access from the Google Account that is logged into the the oAuth2.0 system for Google. so the user defiantly has permissions to access this view. i have also made sure that the developer.googleservice email address is added into Google Analytics and it still wont work.

SCOPE:

{
 "issued_to": "140914874329-48n4vvp54irhf2j2hqieev32qukstc8e.apps.googleusercontent.com",
 "audience": "140914874329-48n4vvp54irhf2j2hqieev32qukstc8e.apps.googleusercontent.com",
 "user_id": "113401197174555518304",
 "scope": "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/plus.moments.write https://www.googleapis.com/auth/plus.profile.agerange.read https://www.googleapis.com/auth/plus.profile.language.read https://www.googleapis.com/auth/plus.circles.members.read",
 "expires_in": 3497,
 "access_type": "offline"
}

And it quite clearly says "https://www.googleapis.com/auth/analytics.readonly"

1
oauth2 is not the same as a service account, so if you are mixing them there is probably something wrong with your authentication code. please post your authentication code.DaImTo
I'm not confusing the 2 i have tried both the first failed so i went with fine i will use oAuth2 to connect to the Analytics API. This did work as i get told i'm logged in. Just have no permisions with an account that has all permissions enabled on Google Analytics So all i want is so i can get any method working to the point i can run the data_ga->getBarkermn01
Check the scope. Check the profile id. That error means you don't have accessDaImTo
Updated to data from link to access token scope check and it has analytics.readonly supported so scope does not seem to be the problemBarkermn01

1 Answers

2
votes

You can check a granted token via a call to

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=accessToken.

There, you may see the user id and granted scopes. If you do not have access, your permissions are obviously insufficient.