0
votes

I am trying to integrating facebook sdk with my laravel app.but in my helper class get error

Call to a member function getLoginUrl() on a non-object

My helper class code:

use Facebook\FacebookSession; use Facebook\FacebookRedirectLoginHelper;

class FacebookHelper
{

    private $helper;

    public function __construct(){

return FacebookSession::setDefaultApplication(Config::get('facebook.app_id'), Config::get('facebook.app_secret'));

        $this->$helper = new FacebookRedirectLoginHelper(url('login/fb/callback'));


    }
    public function getUrlLogin()
    {
        return $this->helper->getLoginUrl(Config::get('facebook.app_scope'));
    }
}
1
Constructor methods should never return anything. - CBroe

1 Answers

0
votes

You do return in your constructor before you set the value of $this->helper, that's why you are getting the error.

Replace

public function __construct() {
  return FacebookSession::setDefaultApplication(Config::get('facebook.app_id'), Config::get('facebook.app_secret'));
  $this->$helper = new FacebookRedirectLoginHelper(url('login/fb/callback'));
}

with

public function __construct() {
  FacebookSession::setDefaultApplication(Config::get('facebook.app_id'), Config::get('facebook.app_secret'));
  $this->$helper = new FacebookRedirectLoginHelper(url('login/fb/callback'));
}