I am logging into Facebook using the PHP SDK using Codeigniter. I get a popup for logging into Facebook, click login, but I canβt get the user ID - it always returns 0.
I put the facebook.php and base_facebook.php files in my libraries file and included it as a library in Codeigniter after the tutorial here .
Can someone tell me what they think? I am using the following code -
Browse - Facebook Login Button
<div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId : '<?php echo $this->config->item('facebook_app_id'); ?>', status : true, cookie : true, xfbml : true, oauth : true, }); FB.Event.subscribe('auth.login', function() { window.location='<?php echo base_url(); ?>auth_other/fb_signin/'; }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> <div class="fb-login-button">Login with Facebook</div>
Controller - auth_other / fb_signin
function fb_signin() { $fb_user = null; $fb_config = array( 'appId' => $this->config->item('facebook_app_id'), 'secret' => $this->config->item('facebook_app_secret') ); $this->load->library('facebook',$fb_config); $fb_user = $this->facebook->getUser(); echo $fb_user;
source share