Pablo
Pablo

Reputation: 1141

Laravel FacebookSDK Bundle not working

Mates, I'm programming a facebook application in Laravel that consists in a game and I need to save the final scores. The thing is, that I need to get the user id (of who's playin') in order to save the achieved score to the DB.

I've installed the FacebookSDK bundle that's on Laravel's website, but when I try to define it, i get the following:

App Controller:

<?php

class App_Controller extends Base_Controller {

public $restful = true;    

public function get_check()
{
    // Define FbkSDK
    $facebook = IoC::resolve('facebook-sdk');
    // Get UserId
    $uid = $facebook->getUser();

}    

public function get_game()
{
    // Imprimo la pantalla del juego
}    

}

Error:

Unhandled Exception
Message:

Class facebook-sdk does not exist

Location:

/home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/ioc.php on line 155

Stack Trace:

#0 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/ioc.php(155): ReflectionClass->__construct('facebook-sdk')
#1 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/ioc.php(118): Laravel\IoC::build('facebook-sdk', Array)
#2 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/application/controllers/app.php(10): Laravel\IoC::resolve('facebook-sdk')
#3 [internal function]: App_Controller->get_check()
#4 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/routing/controller.php(325): call_user_func_array(Array, Array)
#5 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/routing/controller.php(285): Laravel\Routing\Controller->response('check', Array)
#6 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/routing/controller.php(165): Laravel\Routing\Controller->execute('check', Array)
#7 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/routing/route.php(153): Laravel\Routing\Controller::call('app@check', Array)
#8 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/routing/route.php(124): Laravel\Routing\Route->response()
#9 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/laravel/laravel.php(167): Laravel\Routing\Route->call()
#10 /home/pablo/htdocs/conamor/CUENTAS/AventuraCenter/pacman/public/index.php(34): require('/home/pablo/htd...')
#11 {main}

I can't get it to work. I've followed all installation's instructions.

Any idea?

Thanks!

Upvotes: 0

Views: 502

Answers (1)

Jason Lewis
Jason Lewis

Reputation: 18665

This does sound like the bundle hasn't been started.

Make sure that the bundle is listed in your application/bundles.php file and is set to auto start.

return array(
   'facebook-sdk' => array('auto' => true)
);

If that's not working then try to manually start the bundle beforehand.

Bundle::start('facebook-sdk');

If you've not used Artisan to install the bundle then remember that the name of the bundles directory should correspond with the key in the application/bundles.php file. If it doesn't then set the location of the bundle.

return array(
   'facebook-sdk' => array('auto' => true, 'location' => 'facebook-sdk-path')
);

This location is relative to the bundles directory.

Lastly, as a debug measure, you can check the IoC containers registry to confirm that (after the bundle is started) the facebook-sdk instance is being bound.

die(var_dump(IoC::$registry));

You should get an array dumped that contains the facebook-sdk. If it's not there, then again, check the first two steps to ensure the bundle has started.

Upvotes: 2

Related Questions