Facebook Login Doesn't Work
I am trying to add Facebook login to my web site.
What I have done?
Created APP on Facebook as Website with Facebook Login
Sandbox mode is off
APP is set to work on localhost.
What is the problem?
I keep getting $user variable's value as 0
example.php in Facebook PHP SDK works just fine!
I can see my APP when I visit Facebook -> Privacy Settings -> Apps. No
matter if I login with my login.php or example.php of Facebook PHP SDK,
the app seems to be added just the same. However while example.php can
retrieve data from facebook, login.php can't.
I copy and paste the codes from example.php to my login.php page (please
check the code below).
Here is my code;
require_once('system/api/facebook/facebook.php');
$facebook = new Facebook(array(
'appId' => '123456',
'secret' => 'abcde12345',
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
if (!$user) echo '<a href="'.$loginUrl.'">Login</a>';
echo '<pre>';
var_dump($user);
echo '</pre>';
Can someone please tell me what is the difference between my login.php and
example.php as I wasted more than 5 hours without no result?
I also Googled and searched SOF without any info which was helpful.
I hope I was able to clearly ask my question and state my problem.
Thank you all for your help and concern.
No comments:
Post a Comment