Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();

like image 530
Pankaj Avatar asked Oct 30 '22 03:10

Pankaj


1 Answers

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

like image 165
Pankaj Avatar answered Dec 05 '22 18:12

Pankaj