4

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.

Homo Sapien
  • 720
  • 2
  • 9
  • 19

3 Answers3

6

I have the same problem and is a bug! use the new version of file FacebookProvider.php here and work!

German
  • 413
  • 4
  • 15
1

I updated to the latest version of Socialite. Now it works!

Homo Sapien
  • 720
  • 2
  • 9
  • 19
0

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!

Cjames
  • 1,852
  • 1
  • 20
  • 23