AuthClient google 中的 Yii2 获取用户属性。 "Undefined index: email"



我在YII2框架中与Google进行身份验证,我需要帮助以获取属性,因为我无法获得用户属性。

我的web.php:

'google' => [
  'class' => 'yiiauthclientclientsGoogle',
             'authUrl' => 'https://accounts.google.com/o/oauth2/auth?display=popup',
             'clientId' => 'xxxxx',
             'clientSecret' => 'xxxxx',
],

我在控制器中的动作:

'auth' => [
   'class' => 'yiiauthclientAuthAction',
   'successCallback' => [$this, 'successCallback'],
   'successUrl' => yiihelpersUrl::to(['selecionar-empresa']),
],

我的成功:

$attributes = $client->getUserAttributes();
$user = User::find()->where(['email'=>$attributes['email']])->one();

,但在成功中返回此错误:

Undefined index: email

任何人都可以帮助我实现这一目标。Tyyyy。

替换

$attributes = $client->getUserAttributes();
$user = User::find()->where(['email'=>$attributes['email']])->one();

与此尝试。

$attributes = $client->getUserAttributes();
$user_email = $attributes['emails'][0]['value'];
$user = User::find()->where(['email'=>user_email])->one();

我希望它对您有用...

最新更新