artdarek / oauth-4-laravel

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

Call to a member function getAuthorizationUri() on null: Facebook Login Issue with Facebook Graph API Version 2.8 #181

Open sw-tt-aniruddhbhavsar opened 7 years ago

sw-tt-aniruddhbhavsar commented 7 years ago

Hi,

I have configured this package with laravel 4.2.17. When i am trying to create login with facebook i am getting an error "Call to a member function getAuthorizationUri() on null". I have created new App in Facebook with version 2.8 and set redirect url in config file same as configured in Facebook App.

facebook login issue

Below is my code in Controller.php:

public function loginWithFacebook() {

// get data from input
$code = Input::get( 'code' );

// get fb service
$return_url = URL::to('/') ."/login/fb/";

$fb = OAuth::consumer( 'Facebook',$return_url );

// check if code is valid

// if code is provided get user data and sign in
if ( !empty( $code ) ) {

    // This was a callback request from facebook, get the token
    $token = $fb->requestAccessToken( $code );

    // Send a request with it
    $result = json_decode( $fb->request( '/me' ), true );

    $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
    echo $message. "<br/>";

    //Var_dump
    //display whole array().
    dd($result);

}
// if not ask for permission first
else {
    // get fb authorization
    $url = $fb->getAuthorizationUri();

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

}

Below is my code in app/config/app.php:

'providers' => array(
    'Artdarek\OAuth\OAuthServiceProvider'
),

'aliases' => array(
    'OAuth' => 'Artdarek\OAuth\Facade\OAuth',
),

I have updated Facebook App client_id and client_secret in my app/config/oauth-4-laravel.php:

Also getting a same issue for Login with Linkedin, Google. Thanks in advance for help.