Search code examples
laravel-5.3laravel-5.4laravel-socialite

Get Email Address from socialite while login with Gmail


I am following this article to login with Google. I am able to redirect to gmail login successfully. Also, it goes to callback url successfully.

Below is my code

public function showGoogleLoginForm() {
    $providerKey = \Config::get('services.google');
    return \Socialite::driver( 'google' )->scopes(['profile', 'email'])->redirect();
}

Problem

I am now trying to check if the callback gives me the email address of the user or not. So that, I could check that user is registered in my database or not.

Is there any way to get the email address in the callback?

I am able to redirect user to gmail login and also I am able to reach my callback method. In the callback method I got error on this code: \Socialite::driver( 'google' )->user()

I got this Error when i used this code \Socialite::driver( 'google' )->user();


Solution

  • I had to enable Google + API to get rid of this error. Everything is working perfectly now.