0

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"

Community
  • 1
  • 1
Barkermn01
  • 6,781
  • 33
  • 83
  • 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. – Linda Lawton - DaImTo Oct 02 '15 at 13:16
  • service account example http://www.daimto.com/google_service_account_php/ Oauth2 example http://www.daimto.com/google-oauth2-php/ – Linda Lawton - DaImTo Oct 02 '15 at 13:18
  • 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->get` – Barkermn01 Oct 02 '15 at 13:52
  • Check the scope. Check the profile id. That error means you don't have access – Linda Lawton - DaImTo Oct 02 '15 at 14:02
  • Updated to data from link to access token scope check and it has analytics.readonly supported so scope does not seem to be the problem – Barkermn01 Oct 02 '15 at 15:01
  • Odds are that you failed to add the service account email to the account. Attempt to call the account summaries list method first to see what accounts the user is authorized to use. – Matt Oct 13 '15 at 02:12
  • @MartinBarker have you got a workaround for this? i'm struggling with the same trouble – Evgeniy Aug 24 '17 at 09:58
  • @ChillyBang no i never could work this out. – Barkermn01 Aug 24 '17 at 10:28

1 Answers1

2

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.

Jan
  • 42,290
  • 8
  • 54
  • 79
  • Martin, then we need more code or the problem lies somewhere else. Did you set the developer key and secret? Is the redirect uri set correctly? How did you initialize the `$client`? Additionally, there is [a basic example](https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/web-php) you may follow. – Jan Oct 02 '15 at 17:31
  • I have followed the basic example hence the "getResults" code is `$this->service->data_ga->get` and i said in my question i have google Login working perfectly this means developer key and secret are set and working that is where the $client is coming from the user system that has the login tied to it, more code does not help this is across 2 models one for Google Login / Client and one for reading analytics As i have said i login (scopes proves that) and i try to query for something that user has access to on analytics all the code i'm using for the is there – Barkermn01 Oct 04 '15 at 21:28