facebook->getUser() always returns 0

Go To StackoverFlow.com

1

I am working with the PHP SDK, I am just testing it at the moment and it looks like getUser is returning 0 after log in. Been reading through the documentation and cant seem to find anything. Below is my the page a user is redirected to after logging in.

<?php

require_once("facebook.php");
$facebook = new Facebook(array('appId' => ???,
                             'secret' => '???'));
$uid = $facebook->getUser;
    if($uid){
    try{
        $user_profile = $facebook->api('/me','GET');
        $params = (array('next' => 'http://fbtest.net23.net/'));
        $logouturl = $facebook->getLogoutUrl($params);
        $message = "<p>You ARE loged in with Facebook :)</p>\n";
        $a = "<a href=\"{$logouturl}\">Logout</a>\n";
        $content = $message . "<br/>\n" . $a;
}
 catch (FacebookApiException $e){
     error_log($e);
     $content = "<p>Dont work!</p>\n";
 }
}
else{
      $params = (array('scope' => 'read_stream, friends_likes'));
      $loginurl = $facebook->getLoginUrl($params);
      $message = "<p>You are NOT loged in with Facebook :(</p>\n";
      $a = "<a href=\"{$loginurl}\">Login with FB</a>\n";
      $content = $message . "<br/>" . $a;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>test</title>
</head>
<body> 

    <?php echo $content;?>

</body>
</html>

The problem is after a user logs in they get the results of the else statement. Any help or suggestions would be much appreciated :).

2012-04-04 20:15
by James Roberts


0

() missing...

$uid = $facebook->getUser();
2012-04-05 10:53
by Madan
Ads