How to make facebook login using sdk-v4 in Kohana Framework

I have read many examples for facebook login in php, but I couldn’t find example for facebook login in OOP – using framework.
I’m new to Kohana framework and I don’t know how to require all classes and where should I put them.

Currently there is error:
ErrorException [ Fatal Error ]: Trait ‘FacebookFacebookRedirectLoginHelper’ not found

This is my code:
Thank you!

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Membership extends Controller_App {


    public function before() {

        parent::before();
 
        define('FACEBOOK_SDK_V4_SRC_DIR', 'facebook-php-sdk-v4-4.0-dev/src/Facebook/');
        require_once( 'facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookSession.php');

        require_once( 'facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookRequestException.php' );
        //require all classes

        $this->template->active = 'membership';

    }


        use FacebookFacebookRedirectLoginHelper;
        use FacebookFacebookRequest;
        use FacebookFacebookResponse;
        use FacebookFacebookSDKException;
        use FacebookFacebookRequestException;
       //use all classes

   

    public function action_fbLogin(){
        if(!isset($_SESSION)){ session_start();}

        $app_id  = ''; //I've set my Facebook App ID
        $app_secret  = ''; // I've set my App secred
        $required_scope     = 'public_profile, publish_actions, email'; 
        $redirect_url  = 'http://myurl';  // my redirect url


        FacebookSession::setDefaultApplication($app_id , $app_secret);
        $helper = new FacebookRedirectLoginHelper($redirect_url);
        $loginUrl = $helper->getLoginUrl();
        $helper = new FacebookRedirectLoginHelper();

        try {
          $session = $helper->getSessionFromRedirect();
        }
         catch(FacebookRequestException $ex) {
            die(" Error : " . $ex->getMessage());
        } catch(Exception $ex) {
            die(" Error : " . $ex->getMessage());
        }



var_dump($session);
if ($session){ 
    $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
    
   
    echo '<pre>';
    print_r($user_profile); 
    echo '</pre>';
   
}else{

    //display login url
    $login_url = $helper->getLoginUrl( array( 'scope' => $required_scope ) );
    echo '<a href="'.$redirect_url.'">Login with Facebook</a>';
echo '<fb:login-button autologoutlink="true" scope="publish_actions,public_profile,email" onlogin="javascript:CallAfterLogin();"></fb:login-button>';
}

   print_r($user_profile); 

      
}
    
    
	

}


Source: facebook

Leave a Reply