问题
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:
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.
来源:https://stackoverflow.com/questions/32907713/google-analytics-php-api-403-insufficient-permission