1
votes

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

1
Does a service account even have access to mydomain.it? Did you give a product name and email address for the app in cloud developer console?DaImTo
Try creating a new Client ID.Stefano Sala
and you are sure you went to Apis & auths -> APis and enabled it?DaImTo
Re-done a new clientID. Same problem. Changed domain. Same problem. It's seem that API isn't enabled but the check is ok.Vittore

1 Answers

0
votes

Enable API SDK in api lists for using with App.