Google Analytics PHP API “(403) Insufficient Permission”

倖福魔咒の 提交于 2019-12-11 22:56:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!