5

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

Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • add those api tags too, like google people api besides laravel tags – Tahir Hussain Mir Aug 19 '17 at 06:13
  • did you check this : (from your above link) Google’s People API documentation seems to suggest that email addresses come back as part of a default query, but that doesn’t seem to be true. To resolve this, you need to add requestMask.includeField as a parameter in the request. – Tahir Hussain Mir Aug 19 '17 at 06:15
  • Can you share some sample code for the callback and redirect? – Pankaj Aug 19 '17 at 06:16
  • I have used java for these api's but i will still check. – Tahir Hussain Mir Aug 19 '17 at 06:21
  • check this and try it -> https://developers.google.com/people/quickstart/php – Tahir Hussain Mir Aug 19 '17 at 06:26
  • When I used socialite, I just created `UserSocial` entity and connected it to `User` entity on first login. Every next login just got user via the relationship. – shukshin.ivan Aug 19 '17 at 11:59
  • I got this error https://i.stack.imgur.com/zarwe.png when i used this code `\Socialite::driver( 'google' )->user();` – Pankaj Aug 19 '17 at 12:02
  • Your error says about problems with project. Did you configure it correct? – shukshin.ivan Aug 19 '17 at 12:10
  • 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()` – Pankaj Aug 19 '17 at 12:19
  • You can't avoid text of the error. https://stackoverflow.com/questions/22870082/getting-error-403-access-not-configured-please-use-google-developers-console-t – shukshin.ivan Aug 19 '17 at 12:27
  • I saw the answer referred by you above. Can you please confirm where can I find the Edit allowed referers? I am searching it in Api -> Credentials – Pankaj Aug 19 '17 at 12:31

1 Answers1

2

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

Pankaj
  • 9,749
  • 32
  • 139
  • 283