Get Email Address from socialite while login with Gmail

我们两清 提交于 2019-12-10 14:25:19

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/45766977/get-email-address-from-socialite-while-login-with-gmail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!