I implemented social login with laravel socialite for facebook and google, and while it works for facebook for google it gives me this error
Client error:
GET https://www.googleapis.com/userinfo/v2/me?prettyPrint=false
resulted in a401 Unauthorized
response: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 (truncated...)
This is my login method:
public function socialLogin($provider, $accessToken)
{
$providerUser = Socialite::driver($provider)->userFromToken($accessToken);
$user = Reader::whereEmail($providerUser->getEmail())->first();
if (!$user) {
$user = Reader::create([
'email' => $providerUser->getEmail(),
'name' => $providerUser->getName(),
]);
}
if ($user) {
$user->comment_count = DB::table(DB::raw('comments'))->where('author_id', $user->id)
->count();
return $user;
}
return $user;
}
I get the access token but when it comes to this line
$providerUser = Socialite::driver($provider)->userFromToken($accessToken);
it shows the error from above. I have to mention that I'm working on an older laravel project that uses laravel 5.2 Can someone help?