Facebook redirect back with a token but user is still null or 0
$settings = $this->social_model->get_facebook_settings();
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => $settings[0]['value'],
'secret' => $settings[1]['value'],
));
// GET CURRENT USER
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// CHECKS IF NOT LOGIN
if($user == 0){
$params = array(
'scope' => 'publish_stream,publish_actions,manage_pages,status_update,offline_access',
'redirect_uri' => site_url('admin/social/add_facebook')
);
$loginUrl = $facebook->getLoginUrl($params);
echo "<script> window.location = '$loginUrl';</script>";
}else{
$user_accounts = $facebook->api('/me/accounts');
foreach ($user_accounts['data'] as $key => $value) {
$this->social_model->insert_facebook_page($value['name'],$value['access_token'],$value['id']);
}
}