Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

flavianojr's avatar

Laravel 5.2 Socialite Email Issue

Hello everybody. First of all i'm pretty new. Please, write your answers with a lot of details if it's possible. My problem is that Socialite don't return the User Email from Facebook. I can get the ID, Name (first_name and last_name returns undefined index, so i changed it to ['name']) and the profile picture. The Facebook Application is checked to return the user email. My Socialite version is 2.0.4 and i'm using the guzzlehttp/guzzle 4.0. I know there is a newer version for Socialite but when i use it, it requires the guzzle/http version 6 or higher and because of that, it returns the cURL error 60: SSL certificate.

Hope you guys can help me. Sorry for the bad english.

0 likes
3 replies
TheNodi's avatar

@flavianojr

I've never used Socialite before, but I suggest you to post the part of your code where you're trying to get the email.

Can you give us more information about the OS version? It's better to solve the cURL issue and upgrade to latest version first rather then check the other problem (there're might have been a change in the facebook api and the older version doesn't know it). Check this thread out and this reply if you're on windows.

1 like
flavianojr's avatar

@TheNodi Here is the Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Socialite;

use App\Http\Requests;

class FacebookController extends Controller
{
    public function redirectToProvider()
    {
        return Socialite::driver('facebook')->redirect();
    }

    /**
     * Obtain the user information from Facebook.
     *
     * @return Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('facebook')->user();

        return dd($user);
    }
}

And the $user comes from a file called FacebookProvider.php by this function:

protected function mapUserToObject(array $user)
{
    $avatarUrl = $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture';

    return (new User)->setRaw($user)->map([
        'id' => $user['id'], 'nickname' => null, 'name' => isset($user['name']) ? $user['name'] : null,
        'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $avatarUrl.'?type=normal',
        'avatar_original' => $avatarUrl.'?width=1920',
    ]);
}

The route that the error appears is the /callback:

Route::get('facebook', 'FacebookController@redirectToProvider');
Route::get('callback', 'FacebookController@handleProviderCallback');
TheNodi's avatar

@flavianojr

What's the output of "dd($user)"? (Be careful to personal information)

Btw, if you're using Windows, check out Laravel Homestead, you can save yourself a lot of problems.

Please or to participate in this conversation.