Laravel Socialite 2.0 Facebook Authentication only returning id and name

笑着哭i 提交于 2019-12-19 08:56:52

问题


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.


回答1:


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




回答2:


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




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!