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 have the same problem and is a bug! use the new version of file FacebookProvider.php here and work!
I updated to the latest version of Socialite. Now it works!
For thoose who are confused on how to update into the latest version just add this into your composer.json file.
"laravel/socialite": "2.*"
and into your terminal composer update
Cheers!
来源:https://stackoverflow.com/questions/31370907/laravel-socialite-2-0-facebook-authentication-only-returning-id-and-name