artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
685 stars 217 forks source link

Failed to request resource on Google Oauth artdarek. #159

Open chritechs opened 8 years ago

chritechs commented 8 years ago

I have searched online for solution to his problem, but i am yet to find a fix. please i need help..

I get this error : OAuth \ Common \ Http \ Exception \ TokenResponseException Failed to request resource.

Below is my code, if i am doing anything wrong then please help spot it... I have tried using my Redirect URL manually but it still gives the same error..

public function loginWithGoogle() {

$code= Input::get('code'); 

$googleService = OAuth::consumer('Google');

if (!empty($code)){

    $token= $googleService->requestAccessToken($code);
    $result= json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo' ), true);

} else {
        // get googleService authorization
        $url = $googleService->getAuthorizationUri();

        // return to google login url
        return Redirect::to( (string)$url );
    }

}