PHP-API GMAIL-检查用户是否存在

时间:2018-09-06 15:42:17

标签: php api gmail php-7 php-5.5

我正在尝试通过API在gmail中创建用户,并且通过此代码来实现,我在其中传递了类型为user的对象并执行以下操作(此代码有效)

<?php
$scopes = implode(' ', [
    Google_Service_Directory::ADMIN_DIRECTORY_USER
]);


try {
    $file = '/home/test/confing/test.json';
    $client = new Google_Client();
    $client->setApplicationName('test');
    $client->setScopes($scopes);
    $client->setSubject($user->email);
    $client->setAuthConfig($file);
}
catch (\Exception $exception) {
    dump($exception->getMessage());
    die();
}


$service = new Google_Service_Directory($client);

$userObj = new Google_Service_Directory_User(
    array(
        "name" => array("givenName" => "{$user->name}", "familyName" => "{$user->first_name}"),
        "primaryEmail" => "{$user->email}",
        "password" => sha1("123456789")
    )
);


$newUser = $service->users->insert($userObj);
$createdUser = $newUser->primaryEmail;
?>

我遇到的问题是,在创建用户之前,我想进行API调用以检查用户是否存在,并且我不知道该怎么做。有谁能够帮助我。预先感谢

0 个答案:

没有答案