0
나는 다음은Googlephpapi 관리 사용자는
https://www.googleapis.com/auth/admin.directory.group
https://www.googleapis.com/auth/admin.directory.user
https://www.googleapis.com/auth/admin.directory.customer
https://www.googleapis.com/auth/admin.directory.domain
의 관리 콘솔에서 내 서비스 계정의 클라이언트 ID의 범위를 추가했습니다 여기에 방향 https://developers.google.com/api-client-library/php/auth/service-accounts
따랐습니다 코드가 내가
putenv('GOOGLE_APPLICATION_CREDENTIALS=JSONFILELOCATION');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setApplicationName("Directory");
$client->setScopes(array(
Google_Service_Directory::ADMIN_DIRECTORY_CUSTOMER,
Google_Service_Directory::ADMIN_DIRECTORY_USER
));
$client->setSubject("[email protected]");
//$client->setSubject(SUPERADMINEMAILADDRESS);
$service = new Google_Service_Directory($client);
// Print the first 10 users in the domain.
$optParams = array(
'domain'=>'MYDOMAIN',
'maxResults' => 10,
'orderBy' => 'email',
);
$results = $service->users->listUsers($optParams);
내가 얻을 결과를 실행하기 위해 노력하고있어 권한이없는 클라이언트에게
입니다Fatal error: Uncaught exception 'Google_Service_Exception' with message '{
"error": "unauthorized_client",
"error_description": "Unauthorized client or scope in request."
}
' in /var/web/composer/googlephpapi/vendor/google/apiclient/src/Google/Http/REST.php:118
Stack trace:
#0 /var/web/composer/googlephpapi/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#2 /var/web/composer/googlephpapi/vendor/google/apiclient/src/Google/Task/Runner.php(181): call_user_func_array(Array, Array)
#3 /var/web/composer/googlephpapi/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run()
#4 /var/web/composer/googlephpapi/vendor/google/apiclient/src/Google/Client.php(781): Google_Http_REST::execute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), in /var/web/composer/googlephpapi/vendor/google/apiclient/src/Google/Http/REST.php on line 118
서비스 계정 이메일 주소를 사용하려고합니다. 하지만 권한 오류가 발생합니다. 최고 관리자 이메일 주소를 사용하면 결과가 정상적으로 보입니다. 서비스 계정을 사용하기 위해 누락 된 설정이 있습니까? 도메인 전체의 위임을 수행하면 실제 사용자를 사용하지 않고도 서비스 계정을 사용하여 전체 액세스 권한을 가질 수 있다고 생각했습니다.
서비스 계정이 최고 관리자가 아니기 때문에 권한이없는 '클라이언트'가되는 것입니다. 서비스 계정을 사용하여 ** 사용자로 가장 할 수 있습니다 **. 따라서 제목은 항상 계정의 최고 관리자 여야합니다. – Morfinismo