我正在尝试让用户与Google GSuite for Education关联的组。
我已经开始按照本教程列出与该关联相关的所有用户,但是我得到了:错误400-“ message”:“无效的输入。
到目前为止,我已经创建了一个带有服务帐户的项目,因为我需要没有用户交互,因为必须自动完成获取。
之后,我将该帐户设置为启用了G Suite域范围授权,并将其放入具有https://www.googleapis.com/auth/admin.directory.group.readonly和https://www.googleapis.com/auth/admin.directory.user.readonly域的授权API客户端中,但是当我运行代码时,出现上面的错误
这是代码:
<?php
require_once './google-api/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/Culturalia.json');
function getGoogleclient() {
return getServiceaccountClient();
}
function getServiceaccountClient() {
try {
// Create and configure a new client object.
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope([Google_Service_Directory::ADMIN_DIRECTORY_USER_READONLY]);
return $client;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
$client = getGoogleclient();
$service = new Google_Service_Directory($client);
// Print the first 10 users in the domain.
$optParams = array(
'customer' => 'my_customer','maxResults' => 10,'orderBy' => 'email',);
$results = $service->users->listUsers($optParams);
if (count($results->getUsers()) == 0) {
print "No users found.\n";
} else {
print "Users:\n";
foreach ($results->getUsers() as $user) {
printf("%s (%s)\n",$user->getPrimaryEmail(),$user->getName()->getFullName());
}
}
?>
但是我想这很可能是我在某处缺少的授权,我们将不胜感激。