CodeIgniter Forums
Facebook Connect - class init problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Facebook Connect - class init problem (/thread-41295.html)



Facebook Connect - class init problem - El Forum - 05-04-2011

[eluser]jmadsen[/eluser]
I'll go ahead and feel silly in front of everyone, cuz I can't spot what the issue here is, though I suspect it will be a real groaner. maybe describing it will jog something in my mind.

i am doing a Facebook Connect integration with CI2.0, based on this guy's work:

http://hitsend.ca/2010/10/facebook-connect-user-authentication-using-the-new-graph-api-in-codeigniter/

which I've upgraded to 2.0

some relevant code bits are:

config/facebook.php:
Code:
$config['facebook_api_key'] = 'xxx';  (it is the ID, not the key, as he misnamed his array key)
$config['facebook_secret_key'] = 'xxx';


controllers/fb_login.php
Code:
function index() {
        $this->load->library('fb_connect');

libraries/fb_connect.php
Code:
include(APPPATH.'libraries/facebook/facebook.php');

    class fb_connect {
          ....

        function fb_connect()
        {
            //Using the CodeIgniter object, rather than creating a copy of it
            $this->_obj =& get_instance();
            
            //loading the config paramters for facebook (where we stored our Facebook API and SECRET keys
            $this->_obj->load->config('facebook');
            //make sure the session library is initiated. may have already done this in another method.
            $this->_obj->load->library('session');
            
            $this->_api_key        = $this->_obj->config->item('facebook_api_key');
            $this->_secret_key    = $this->_obj->config->item('facebook_secret_key');

            $this->appkey = $this->_api_key;

            //connect to facebook
            $this->fb = new Facebook(array(
                          'appId'  => $this->_api_key,
                          'secret' => $this->_secret_key,
                          'cookie' => true
                        ));

and finally, the facebook php library:
libraries/facebook/facebook.php
Code:
public function __construct($fb_config) {
print_r($fb_config);
    $this->setAppId($fb_config['appId']);
    $this->setApiSecret($fb_config['secret']);
    if (isset($fb_config['cookie'])) {
      $this->setCookieSupport($fb_config['cookie']);
    }


The best way I can describe the issue is just to give you the output of print_r($fb_config):

Code:
Array ( [facebook_api_key] => xxx [facebook_secret_key] => xxx)

and
Message: Undefined index: appId
Message: Undefined index: secret

The facebook __construct() has been loading with the config file's $config[] array; no idea why it is doing this.

Thanks in advance for any leads or spottings of "dumb things I've done"


Facebook Connect - class init problem - El Forum - 05-25-2011

[eluser]michaelbenbender[/eluser]
I'm not sure this answers your question, but Facebook just released an updated PHP SDK the other day. http://developers.facebook.com/blog/post/503

You can put these two PHP files in your libraries folder and use them directly as in the examples in that blog by using
Code:
$this->load->library('facebook');
$this->facebook...
(Use $this->facebook instead of $facebook as in the examples in the blog post.)

I have not dealt with facebook connect, but I was under the impression that is the old legacy facebook integration process and that the graph API is the new way (and much easier in my opinion).


Facebook Connect - class init problem - El Forum - 07-13-2011

[eluser]Nisha S.[/eluser]
I have wrote a library and you can get it from http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter which is based on new SDK.


Facebook Connect - class init problem - El Forum - 07-13-2011

[eluser]jmadsen[/eluser]
sorry - never came back to answer this. it was "a real groaner" as i suspected - a class conflict with a previously installed facebook_connect library I didn't know about :-(