Facebook getUser () returns 0

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; 
+6
source share
5 answers

I ran into a similar problem, here is a solution that may help you.

 $facebook = new Facebook(array( 'appId' => 'xxxx', 'secret' => 'xxxxx', "redirect_uri" => "set the uri to point to the same page" )); $user = $facebook->getUser(); if($user) { //your task } else { header('location:'. $facebook->getLoginUrl()); } $user = $facebook->getUser(); if($user) { //your task } else { header('location:'. $facebook->getLoginUrl()); 

}

+1
source

I got into a situation where getUser () returned 0, when it really should not be, the application was still isolated. It turns out the user did not accept the request to be an application developer.

0
source

I ran into a similar problem. I used a sample project and could not understand why it keeps returning 0. I tried almost all the linked links here, but no one solved it.

The solution was updating the SDK files for Facebook in a sample project. Simple and easy to skip

0
source

I had the same problem, after a long time trying to figure out what the problem was, I found that you need an access token in order to get the user ID. To obtain an access token for the signed_request form, the user must first allow (in order to get permissions) the application. I hope this helps

0
source

If the application domain is the real domain, but the site URL is localhost, the getUser function returns 0

-1
source

Source: https://habr.com/ru/post/904686/


All Articles