Я выполнил вход через Google, используя Google_Client на своем php-сайте.
Вход выполнен успешно, но я пытаюсь получить информацию о пользователях, которые вошли в систему, но не получают ее.
Нижемой код.
$gClient = new Google_Client();
$gClient->setApplicationName('Login to -------');
$gClient->setClientId(GOOGLE_CLIENT_ID);
$gClient->setClientSecret(GOOGLE_CLIENT_SECRET);
$gClient->addScope(Google_Service_Oauth2::USERINFO_PROFILE);
$gClient->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$gClient->addScope(Google_Service_Oauth2::PLUS_LOGIN);
$gClient->setAccessType('offline'); // offline access
$gClient->setIncludeGrantedScopes(true); // incremental auth
$gClient->setRedirectUri(WEB_PANEL_PATH);
$google_code = $gh->read('code');
$objOAuthService = new Google_Service_Oauth2($gClient);
if (!empty($google_code)) {
$gClient->authenticate($google_code);
$_SESSION['access_token'] = $gClient->getAccessToken();
$outputjson['active'] = $_SESSION['access_token'];
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$gClient->setAccessToken($_SESSION['access_token']);
}
if($gClient->getAccessToken()) {
$userData = $objOAuthService->userinfo->get();
if(!empty($userData)) {
}
$outputjson['user_data'] = $userData;
$outputjson['access_token'] = $gClient->getAccessToken();
}else{
$outputjson['login_url'] = $gClient->createAuthUrl();
}
$outputjson['session'] = $_SESSION;
$outputjson['success'] = '1';
$ userData всегда равен нулю.
Отправляет запрос в oauth2 / v2 / userinfo, но не получает никаких данных.
[methods:Google_Service_Resource:private] => Array
(
[get] => Array
(
[path] => oauth2/v2/userinfo
[httpMethod] => GET
[parameters] => Array
(
)
)
)