1

这是登录后将重定向到的网页:

// get_user_info.php
<?
    $gClient = new \Google_Client();
    $gClient->setApplicationName('Login to Pronexo');
    $gClient->setRedirectUri('http://localhost/pronexo/public/login/login_through_api/');
    $gClient->setClientId('849746924921-ueqhqvtbb6l7ccfrcq4j405bvej03bm7.apps.googleusercontent.com');
    $gClient->setClientSecret('W7DdT0QmATW-3ZVJMO55jsfY');
    $gClient->addScope("https://www.googleapis.com/auth/userinfo.profile");
    $gClient->addScope("https://www.googleapis.com/auth/userinfo.email");
    $oauth2 = new \Google_Service_Oauth2($gClient);
    $userInfo = $oauth2->userinfo;
    echo "<pre>";
    print_r($userInfo);
    die;

结果是这样的:

在此处输入图像描述

这是结果Google_Client {#229 > }

在此处输入图像描述

我也检查了结果的所有项目,但没有用户信息。如您所知,我必须获取通过 google php api 登录到我的网站的用户的电子邮件、姓名等。无论如何,知道如何访问该信息吗?

4

0 回答 0