Q:

facebook php sdk $this->getUser always returning 0

I have searched a lot for this question and found no particular solution for this question.I have seen many examples and so-called solutions but none of them have worked.
On top of that I am doing this watching a video by phpacademy and typing exactly as the video.
Before anyone mark this as a duplicate my only question is 
Is this because I am testing this in local machine?
Because the only difference between my setting and the video is that the tutorial is hosted live and I am testing this in my local machine.
If this is the case?How can I test PHP facebook SDK in my local machine?
Here is my complete code
this is my main controller  
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Fbapp extends MX_Controller {

    function __construct() {
        $this->load->library('fbconnect');
        parent::__construct();
    }
    function index() {

        echo "<a href='" . base_url() . "fbapp/gotofb'>Go To Facebook</a>";
    }

    function gotofb(){

        $data = array(
            'redirect_uri' => base_url() . "fbapp/redirected",
            'scope' => "email,photo_upload"
        );
      $url =  $this->fbconnect->getLoginUrl($data);

     redirect($url);
    }

    function redirected(){
        $user_id= $this->fbconnect->getUser();
       echo $user_id;

    }
}

This is my library file that I have named "fbconnect.php",included sdk files inside libraries and incuded in library and I have created a facebook.php inside config which stores appId and secret which i have loaded as $config.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH . 'libraries/facebook/src/facebook.php');
class Fbconnect extends Facebook{

    public $user = null;

    function __construct() {
        $ci =& get_instance();

        $ci->load->config("facebook", true);
        $config = $ci->config->item('facebook');

        parent::__construct($config);
    }

}

Steps:
1.i access my url .I click on the link.
2.it get me to the login page of facebook. I login.
3. it redirects me to the redirect uri and prints 0.
Note:I am developing in codeigniter.
Thanks in advance.
Any help is super appreciated!!

A:

I had same problem before, after days f searching i solved it in two ways if you are sure about all configuration ... I think you have to solutions to try:
1- host your application on web hosting server and try it with the domain your will get.
2- use javascript sdk to get the access_token then pass it to php skd, like this:
              window.fbAsyncInit = function() {
            FB.init({
              appId      : 'appId', // App ID
              channelUrl : 'channel.html', // Channel File
              status     : true, // check login status
              cookie     : true, // enable cookies to allow the server to access the session
              xfbml      : true  // parse XFBML
            });
            // Additional init code here

            FB.Event.subscribe('auth.login', function(response) {
            var accessToken = response.authResponse.accessToken;
            window.location.href = "http://page_to_read_process_the _request?"accessToken="+accessToken;
         });

in php you only shoudl do like this:
$facebook->setAccessToken($accessToken);
$facebook->getUser();

if this solved your problem: please do not forget to vote :D 

