When I run this code:
$client = new \Google_Client();
$client->setApplicationName($application_name);
$client->setClientId($client_id);
$key = file_get_contents('Google.p12');
$secret = file_get_contents('Google.json');
$cred = new \Google_Auth_AssertionCredentials(
$email_address, array(
'https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/admin.directory.group'
), $key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer');
$client->setClientSecret($secret);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$token = $client->getAccessToken();
$client->setAccessToken($token);
$this->service = new \Google_Service_Directory($client);
$adminOptParams = array('domain' => 'mydomain.it');
$results = $this->service->users->listUsers($adminOptParams);
foreach ($results as $item) {
print_r($item);
}
I get this error:
[Google_Service_Exception]
Error calling GET https://www.googleapis.com/admin/directory/v1/users?domai
n=mydomain.it: (403) Access Not Configured. Please use Google Developers C
onsole to activate the API for your project.
Note that in Google app admin console I already done:
client_id --> approved api --> https://www.googleapis.com/auth/admin.directory.group https://www.googleapis.com/auth/admin.directory.orgunit https://www.googleapis.com/auth/admin.directory.user