Get email address from socialite user when logging in to Gmail

I follow this article in login with Google . I can redirect to gmail login successfully. In addition, it successfully returns to the callback URL.

Below is my code

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

Problem

Now I'm trying to check if the callback gives me the email address of the user or not. Thus, I could verify that the user is registered in my database or not.

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

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

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

+5
source share
1 answer

I had to enable the Google + API to get rid of this error. Now everything works fine.

+2
source

Source: https://habr.com/ru/post/1271011/


All Articles