(403)使用Google_Service_Directory未配置访问权限

时间:2014-09-17 19:45:48

标签: 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 \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应用管理控制台中,我已经完成了:

client_id - >批准的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 个答案:

答案 0 :(得分:0)

在api列表中启用API SDK,以便与App一起使用。