Welcome Guest, Not a member yet? Register   Sign In
Problems importing facebook client library
#1

[eluser]igniteflow[/eluser]
Hi all,
I'm trying to import the facebook library to use in an application. I have put the following very basic code in my controller constructor:

Code:
class Home extends Controller {
        
        public $fb;
        public $fb_user;
        
        function Home()
        {
        parent::Controller();
            
        $this->load->helper('url');
            
            $this->load->library('facebook-client/facebook');
            $this->fb = new Facebook('xxx', 'xxx');
            $this->fb_user = $this->facebook->require_login();
        }

        function facebook() {
            $this->load->view('facebook_view');
        }

which when run i get the following errors

Code:
A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Facebook::__construct(), called in /home/fhlinux132/f/fantasyrecords.co.uk/user/htdocs/facebook/hollyoaks-connect/system/libraries/Loader.php on line 928 and defined

Filename: facebook-client/facebook.php

Line Number: 64
A PHP Error was encountered

Severity: Warning

Message: Missing argument 2 for Facebook::__construct(), called in /home/fhlinux132/f/fantasyrecords.co.uk/user/htdocs/facebook/hollyoaks-connect/system/libraries/Loader.php on line 928 and defined

Filename: facebook-client/facebook.php

Line Number: 64
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: api_key

Filename: facebook-client/facebook.php

Line Number: 65
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: secret

Filename: facebook-client/facebook.php

Line Number: 66
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: api_key

Filename: facebook-client/facebook.php

Line Number: 68
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: secret

Filename: facebook-client/facebook.php

Line Number: 68

However, this code works fine in plain PHP when I just write

Code:
require_once('facebook-client/facebook.php');
$facebook = new Facebook(API_KEY,SECRET_CODE);

can anyone tell me what I'm doing wrong here?
#2

[eluser]igniteflow[/eluser]
Solved it, by putting

Code:
/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for controller types and some third-party libraries.
|
*/
function __autoload($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        $class = APPPATH . 'classes/'. $class . EXT;
        $lib = APPPATH . 'libraries/'. $class . EXT;

        if(file_exists($class))
        {
            include_once( $class );
        }

        else if(file_exists($lib))
        {
            include_once( $lib );
        }
    }
}

in config.php. I doubt this is the most efficient way of including a class in CI though, and would like to hear the best way to do it...
ps. the above method was posted by phil at stackflow
#3

[eluser]Unknown[/eluser]
I'm still have that problem. I've put this code in the config.php, but doesn't worked.




[quote author="igniteflow" date="1267726301"]
Code:
/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for controller types and some third-party libraries.
|
*/
function __autoload($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        $class = APPPATH . 'classes/'. $class . EXT;
        $lib = APPPATH . 'libraries/'. $class . EXT;

        if(file_exists($class))
        {
            include_once( $class );
        }

        else if(file_exists($lib))
        {
            include_once( $lib );
        }
    }
}
[/quote]

And then, these messages started to show.

Code:
A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Facebook::__construct(), called in /home/project/system/libraries/Loader.php on line 928 and defined

Filename: libraries/facebook.php

Line Number: 165
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: config

Filename: libraries/facebook.php

Line Number: 166
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: config

Filename: libraries/facebook.php

Line Number: 167


Somebody know how can I resolve that?




Theme © iAndrew 2016 - Forum software by © MyBB