i'm using laravel 5 Socialite and this to create social login https://github.com/laravel/socialite. When i use this function and when i ran into this $facebook->getEmail();
the email i get it's null
public function FacebookInfo()
{
$facebook = Socialite::driver('facebook')->user();
$user= new User();
$user-> username =$facebook->getNickname();
$user-> full_name =$facebook->getName();
$user-> avatar=$facebook->getAvatar();
$user-> email =$facebook->getEmail();
$user-> remember_token =$facebook->token;
$user ->level=1;
$user-> total_post = 0;
$user->save();
return redirect()->intended('/');
}
So any suggest for this problem? Thanks in advanced
You have to mention what all fields do you want from Facebook. You can do this by adding a scope
while redirecting to Facebook for authentication like below,
return Socialite::driver('facebook')->scopes(['public_profile','email', 'user_friends'])->redirect();
You can learn more about Facebook permissions here.
P.S. Now Facebook also allows mobile number to create an account instead of an email. In that case you will not get an email!!!