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