1

使用下面的代码,我可以成功创建新用户。但是,如果用户已经存在,则它不起作用。那么,当我的域中不存在用户时,如何运行此代码。

我的代码是

$dir = new Google_Service_Directory($client);

$user = new Google_Service_Directory_User();

$name = new Google_Service_Directory_UserName();

$firstname=$_POST['first_name'];

$familyname=$_POST['last_name'];

$primary_email= $firstname.'.'.$familyname.'@mydomainname.com';

$name->setGivenName($firstname);
$name->setFamilyName($familyname);
$user->setName($name);
$user->setHashFunction("SHA-1");
$user->setPrimaryEmail($primary_email);
$user->setPassword(hash("sha1","password"));

$result = $dir->users->insert($user);
echo "New user ".$result->primaryEmail." created successfully.";
4

0 回答 0