哪个api用于通过php中的oauth获取已验证用户的用户名


Which api is used to get username of authenticated user via oauth in php?

我在我的门户网站中用php进行了谷歌身份验证。现在我想访问经过身份验证的用户的名称和电子邮件地址,那么使用哪个api来实现这一点呢?代码:

<?php
    // put your code here
    require_once 'app/init.php';
    $googleClient = new 'Google_Client();
    $auth = new 'GoogleAuth($googleClient);
    if ($auth->checkRedirectCode()) {
        header('Location : index.php');
    }
?>
<?php if (!$auth->isLoggedIn()): ?>
    <h2>Login to your account</h2>
    <a href="<?php echo $auth->getAuthUrl(); ?>"><img src="img/gbtn.png"></a>
    <hr>
<?php endif; ?>

你会得到这样的结果:

$user = $client->getAuthService()->userinfo->get();
                        $user_id = $user['id'];
                        $user_name = filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS);
                        $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
                        $profile_url = filter_var($user['link'], FILTER_VALIDATE_URL);
                        $profile_image_url    = filter_var($user['picture'], FILTER_VALIDATE_URL);