Hello Friends,
I'm having problem to use the Directory Service API. I'm developing a application to manage the user accounts of my business, but i can't connect the API. I'm using:
require_once 'tarefas2/src/Google_Client.php';
require_once 'tarefas2/src/contrib/Google_DirectoryService.php';
$key = file_get_contents('myprivatekey.p12');
$client = new Google_Client();
$client->setApplicationName("googleapi");
$client->setUseObjects(true);
$client->setAssertionCredentials($auth);
$service = new Google_DirectoryService($client);
$results = $service->groups->listGroups(array('domain' => 'mydomain.gov.br')); print '<h2>Response Result:</h2><pre>' . print_r($results, true) . '</pre>';
I activated the api on api console. I'm getting this error:
Fatal error: Uncaught exception 'Google_AuthException' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "access_denied", "error_description" : "Requested scopes not allowed: https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/admin.directory.group" }'' in /var/www/html/xxxxxxx/front/tarefas2/src/auth/Google_OAuth2.php:288 Stack trace: #0 /var/www/html/xxxxxxx/front/tarefas2/src/auth/Google_OAuth2.php(265): Google_OAuth2->refreshTokenRequest(Array) #1 /var/www/html/xxxxxx/front/tarefas2/src/auth/Google_OAuth2.php(218): Google_OAuth2->refreshTokenWithAssertion() #2 /var/www/html/xxxxxx/front/tarefas2/src/service/Google_ServiceResource.php(167): Google_OAuth2->sign(Object(Google_HttpRequest)) #3 /var/www/htmlxxxxxxx/front/tarefas2/src/contrib/Google_DirectoryService.php(188): Google_ServiceResource->__call('list', Array) #4 /var/www/html/xxxxx/front/tarefas2.php(22): Google_GroupsServiceResource->listGroups(Array) #5 {main} thrown in /var/www/html/xxxxxxx/front/tarefas2/src/auth/Google_OAuth2.php on line 288
Anybody had the same problem?
Sorry my english