1
votes

Hello guys I am using socialite package with laravel to login the user via facebook provider everything is working great except that when i ask for the profile avatar . it does not return the real facebook profile photo of the user but instead it returns that default facebook avatar that you get when you create a new facebook account. this is the default facebook avatar that is being returned which is not the real profile picture of the user(https://i.stack.imgur.com/l60Hf.png) here is my code

   /**
 * Redirect the user to the Facebook authentication page.
 *
 * @return \Illuminate\Http\Response
 */
public function redirectToFacebookProvider()
{
    return Socialite::driver('facebook')->redirect();
}

/**
 * Obtain the user information from Facebook.
 *
 * @return \Illuminate\Http\Response
 */
public function handleFacebookProviderCallback()
{
    $facebookUser = Socialite::driver('facebook')->user();
    $user = User::firstOrCreate([
        'email'=>$facebookUser->getEmail()
    ], [
        'name' => $facebookUser->getName(),
        'email' => $facebookUser->getEmail(),
        'avatar'=>$facebookUser->getAvatar(),
    ]);

    Auth::login($user , false);
    return redirect()->route('user.dashboard');
}
1

1 Answers

0
votes

Get the URL of getAvatar() then include this parameter in url &access_token=YOURTOKEN