Laravel Socialite 2.0 Facebook验证只返回ID和名称 [英] Laravel Socialite 2.0 Facebook Authentication only returning id and name

查看:266
本文介绍了Laravel Socialite 2.0 Facebook验证只返回ID和名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel的Socialite包(2.0.0版)。这对Google和github是非常有用的,但是当我尝试使用Facebook登录时,我得到以下信息:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆