dongwen1909 2017-02-09 10:05 采纳率: 0%
浏览 114

使用Google Analytics API获取所有帐户的用户

I am having problems getting a list of users for accounts

If I put the account number in the try me page (https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountUserLinks/list) it works

$client = new Google_Client();
$client->setAuthConfigFile($_SERVER['DOCUMENT_ROOT'] . '/client_secrets.json');
$client->addScope(Google_Service_Analytics::ANALYTICS_MANAGE_USERS);

$client=gaGetClient();
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
     $client->setAccessToken($_SESSION['access_token']);
     $analytics = new Google_Service_Analytics($client);
     //this doesn't work
     $accountUserlinks=$analytics->management_accountUserLinks->listManagementAccountUserLinks('123456');
     //this works
     $man_accounts = $analytics->management_accounts->listManagementAccounts();
      $accounts = [];
      foreach ($man_accounts['items'] as $account) {
           $accounts[] = [ 'id' => $account['id'], 'name' => $account['name'] ];
           echo $account['name'] . " (" . $account['id'] . ")<br/>";
      }
}

I get this error message

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management/accounts/123456/entityUserLinks: (403) Insufficient Permission' in /home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php:110 Stack trace: #0 /home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 /home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array) #3 /home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php(46): Google_Task_Runner->run() #4 /home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Goo in /home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php on line 110

Can anyone think what I am doing wrong. I am thinking it is a scope issue, but I have stated my scopes

Thanks

Grant

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler