CodeIgniter Forums
Facebook Connect with codeignitor - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Facebook Connect with codeignitor (/showthread.php?tid=24666)

Pages: 1 2 3 4


Facebook Connect with codeignitor - El Forum - 03-11-2010

[eluser]garycocs[/eluser]
Lads I have the same issue now with the sessions:

Code:
Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Session key invalid or no longer valid' in public_html/samplesite/system/application/libraries/facebook-client/facebookapi_php5_restlib.php:1915 Stack trace: #0 public_html/samplesite/system/application/libraries/facebook-client/facebookapi_php5_restlib.php(786): FacebookRestClient->call_method('facebook.users....', Array) #1 public_html/samplesite/system/application/libraries/facebook_connect.php(57): FacebookRestClient->users_getInfo('750791302', Array) #2 public_html/samplesite/system/application/libraries/facebook_connect.php(42): Facebook_connect->_manage_session() #3 public_html/samplesite/system/libraries/Loader.php(928): Facebook_connect->Facebook_connect() #4 public_html/samplesite/system/libraries/Loader.php(829): CI_Loader->_ci_init_class('facebook_connec...', '', NULL, NULL) #5 public_html/samplesite/system/libraries/L in public_html/samplesite/system/application/libraries/facebook-client/facebookapi_php5_restlib.php on line 1915

I see above talk of solutions etc but can't seem to find them anywhere, any help with this?

When I clear the session by deleting the chache in FF it goes back to working fine!!

Thanks
Gary


Facebook Connect with codeignitor - El Forum - 03-27-2010

[eluser]Deadly[/eluser]
Getting the same thing here, but no luck thus far. I think Haughin has moved on from this library, hasn't been updated in some time... 8-(


Facebook Connect with codeignitor - El Forum - 03-27-2010

[eluser]Deadly[/eluser]
[quote author="darkhouse" date="1265331573"]The facebook connect library works great for logging in allowing users to use the application - but I've got an issue, even in the example that came with the library, where if I want to use any of the functions in the client class, it just kills the site, no error (error reporting is on and everything, I get errors for other things, like if I omit a required parameter from a method call).

In the example it came with, I uncommented the line $this->facebook_connect->client->events_get($data['user_id']); It breaks. White screen, no error. Not sure what it's doing, I might have to dig into the code of the library to figure it out (which sucks because I'm under the gun as it is).

Has anybody else run into this, or know what might be causing it?

Edit: I found out the reason I'm getting a blank screen. The call_method method is trying to throw an error, but the error isn't being displayed (not sure why). So for now, I'm just doing die($result['error_msg']); which at least gives me the error message. Turns out it's "Session key invalid or no longer valid". There are a number of fixes for this issue on Elliot's site, but I've tried them all and nothing's working. Any ideas?

Edit 2: Turns out I had missed a "fix" on Elliots comments area. Pjerky had the solution I was looking for and now everything seems to be working marvelously. Great library!

Thanks.[/quote]

Elliot's taken the comments of his site now, so I can't find Pjerky's response. Are you able to repost here?

EDIT: Found it here: http://www.backtype.com/url/www.pjerky.com?page=2


Facebook Connect with codeignitor - El Forum - 03-28-2010

[eluser]garycocs[/eluser]
I managed to sort it out after, let me know if you need help with it!!!


Facebook Connect with codeignitor - El Forum - 03-28-2010

[eluser]Deadly[/eluser]
Hey, sure, any insights you could share would be great. I tried the fix above but no love!


Facebook Connect with codeignitor - El Forum - 03-29-2010

[eluser]garycocs[/eluser]
So this is what it turned out like for me, it's a couple of weeks ago now but it works ok I think?
Code:
<?php
/**
* CodeIgniter Facebook Connect Library (http://www.haughin.com/code/facebook/)
*
* Author: Elliot Haughin (http://www.haughin.com), [email protected]
*
* VERSION: 1.0 (2009-05-18)
* LICENSE: GNU GENERAL PUBLIC LICENSE - Version 2, June 1991
*
**/


    include(APPPATH.'libraries/facebook-client/facebook.php');

    class Facebook_connect {

        private $_obj;
        private $_api_key        = NULL;
        private $_secret_key    = NULL;
        public     $user             = NULL;
        public     $user_id         = FALSE;
        public     $info            = NULL;
        
        public $fb;
        public $client;

        function Facebook_connect()
        {
            $this->_obj =& get_instance();

            $this->_obj->load->config('facebook');
            $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->fb = new Facebook($this->_api_key, $this->_secret_key);
            
            $this->client = $this->fb->api_client;
                        
            if($this->fb->get_loggedin_user()) {
                try {
                    //Get some sample data from facebook, you can do whatever you want here really..
                    $this->user_id = $this->client->fql_query('SELECT uid, pic_square, first_name FROM user WHERE uid = ' . $this->fb->get_loggedin_user());
                } catch (Exception $ex) {
                    //Need to destroy the session. This is the important part!
                    $this->fb->clear_cookie_state();
                }
                $this->user_id = $this->fb->get_loggedin_user();                
            } else {
                $this->user_id = NULL;
            }
            

            $this->_manage_session();

            if ( $this->user_id !== NULL )
            {
                
            }
        }

        private function _manage_session()
        {
            if($this->_obj->session->userdata('facebook_user')){
                $user = $this->_obj->session->userdata('facebook_user');
            }else{
                $user=FALSE;
                }

            if ( $user === FALSE && $this->user_id !== NULL )
            {
                $profile_data = array('uid','first_name', 'last_name', 'name', 'locale', 'pic_square', 'profile_url');
                $info = $this->fb->api_client->users_getInfo($this->user_id, $profile_data);
                if (isset($info[0])) {
                        $user = $info[0];
                        $this->_obj->session->set_userdata('facebook_user', $user);
                    }
            }
            elseif ( $user !== FALSE && $this->user_id === NULL )
            {
                // Need to destroy session
            }

            if ( $user !== FALSE )
            {
                $this->user = $user;
            }
        }
    }



Facebook Connect with codeignitor - El Forum - 03-29-2010

[eluser]Deadly[/eluser]
Hmm. Getting this error now:
Code:
Fatal error: Call to undefined method Facebook::clear_cookie_state()



Facebook Connect with codeignitor - El Forum - 03-29-2010

[eluser]garycocs[/eluser]
Oh ya you should install the latest facebook library too, sorry like I said it's been a while. Just download the facebook files from the facebook dev site and replace those with the files in your app.


Facebook Connect with codeignitor - El Forum - 03-29-2010

[eluser]Deadly[/eluser]
Ah of course, hence the missing function. Done and testing now. Many thanks!


Facebook Connect with codeignitor - El Forum - 03-30-2010

[eluser]Unknown[/eluser]
Hey guys, thanks for posting all of this. I've been struggling with this issue for awhile. Deadly, can you confirm that worked for you? I am putting that code in now, but testing it is difficult because I have to wait for the sessions to expire in order to recreate the white screen.

Thanks again.