Oauth 2.0 (403)未使用Google_服务_目录配置访问

Oauth 2.0 (403)未使用Google_服务_目录配置访问,oauth-2.0,google-api-php-client,Oauth 2.0,Google Api Php Client,当我运行此代码时: $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

当我运行此代码时:

    $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);
    }
我得到这个错误:

[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.
请注意,在Google app管理控制台中,我已经完成了以下操作:

客户id->批准的api->

在API列表中启用API SDK以便与应用程序一起使用。

服务帐户甚至可以访问mydomain.it吗?您是否在cloud developer控制台中提供了该应用的产品名称和电子邮件地址?是。尝试创建一个新的客户端ID。您确定已转到API&auths->API并启用了它?重新创建了一个新的客户端ID。同样的问题。已更改域。同样的问题。似乎API未启用,但检查正常。