Laravel Socialite 2.0 Facebook验证只返回ID和名称 [英] Laravel Socialite 2.0 Facebook Authentication only returning id and name
问题描述
FacebookProvider.php中的ErrorException第89行:
未定义的索引:first_name
在 FacebookProvider中。 php
错误是从这个方法:
protected function mapUserToObject(array $ user)
{
return(new User) - > setRaw($ user) - > map([
'id'=> $ user ['id'],'nickname'=> null ,'name'=> $ user ['first_name']。''$ user ['last_name'],
'email'=> isset($ user ['email'])?$ user [ 'email']:null,'avatar'=> $ this-> graphUrl。'/'。$ this-> version。'/'。$ user ['id']。'/ picture?type = normal ',
]);
}
如果我 dd()
在此映射之前的 $ user
param。我只收到身份证和身份验证的Facebook用户的名字。所以,这意味着我没有收到Facebook用户的电子邮件。我至少需要用户的名称
和电子邮件
。
在 dd()
之后,此方法如下所示:
protected function mapUserToObject(array $ user)
{
dd($ user);
return(new User) - > setRaw($ user) - > map([
'id'=> $ user ['id'],'nickname'=> null,' name'=> $ user ['first_name']。''$ user ['last_name'],
'email'=> isset($ user ['email'])?$ user ['email ']:null,'avatar'=> $ this-> graphUrl。'/'。$ this-> version。'/'。$ user ['id']。'/ picture?type = normal'
]);
}
可能是什么问题?请帮助我。
我更新到最新版本的Socialite。现在它的作品!
I am using Laravel's Socialite package (version 2.0.0). It is working great for google and github but when I try to login with facebook, I get this:
ErrorException in FacebookProvider.php line 89:
Undefined index: first_name
In the FacebookProvider.php
the error is from this method:
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => null, 'name' => $user['first_name'].' '.$user['last_name'],
'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture?type=normal',
]);
}
If I dd()
the $user
param before this mapping. I only get id and the name of the authenticated Facebook user. So, it means that I am not getting the email of the Facebook user. I at least need name
and email
of the user.
After dd()
this method looks like this:
protected function mapUserToObject(array $user)
{
dd($user);
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => null, 'name' => $user['first_name'].' '.$user['last_name'],
'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture?type=normal',
]);
}
What could be the problem? Please help me.
I updated to the latest version of Socialite. Now it works!
这篇关于Laravel Socialite 2.0 Facebook验证只返回ID和名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!