CodeIgniter Forums
Facebook Auth - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Facebook Auth (/showthread.php?tid=52572)



Facebook Auth - El Forum - 06-16-2012

[eluser]Carmichael[/eluser]
Hi, I am having problem with Facebook Auth on my website.

I have facebook.php and facebook_base.php in libraries.

Controller
Quote:<?php
class Auth extends MY_Controller
{

function __construct()
{
parent::__construct();
}

function facebook_auth()
{

$this->view_data['view_title'] = "Facebook Login";

$fb = $this->facebook->getUser();

if ($fb) {
try {
$this->view_data['fb_user'] = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
$fb = null;
}
}

if ($fb) {
$this->view_data['logout_url'] = $this->facebook->getLogoutUrl();
} else {
$this->view_data['login_url'] = $this->facebook->getLoginUrl();
}

}
}
?>

View
Code:
<?php if (@$fb_user): ?>
        <pre>
            &lt;?php echo print_r($fb_user, TRUE) ?&gt;
        </pre>
        <a href="&lt;?php echo $logout_url ?&gt;">Logga ut</a>
    &lt;?php else: ?&gt;
        <h2>Logga in med Facebook</h2>
        <a href="&lt;?php echo $login_url ?&gt;">Logga in</a>
    &lt;?php endif; ?&gt;
    
    &lt;?php echo @$fb_user['first_name']; ?&gt;

The user doesn't get logged in because getUser() returns 0 even when the user hit login.


Facebook Auth - El Forum - 06-18-2012

[eluser]boltsabre[/eluser]
So you're saying:
Code:
$fb = $this->facebook->getUser();
var_dump($fb); // is returning 0?)


If that's the case you'll have to go look in the library and see under what conditions that that method (getUser()) will return 0. Once you have that figured out you should be able to reverse engineer why you cannot log in.

Without the libraries in front of me (I'm at work) I cannot be of much more help, but yeah, you should be able to reverse engineer it pretty easily!


Facebook Auth - El Forum - 06-18-2012

[eluser]Nisha S.[/eluser]
You can download a working code at http://www.betterhelpworld.com/wp-content/uploads/2011/06/Facebook-connect-for-Codeigniter.zip