facebook-> getUser()始终返回0

时间:2012-04-04 20:15:49

标签: facebook-graph-api login facebook-php-sdk fbconnect

我正在使用PHP SDK,我现在只是测试它,看起来getUser在登录后返回0。阅读文档并且似乎找不到任何东西。下面是用户登录后重定向到的页面。

<?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>

问题是在用户登录后他们获得了else语句的结果。任何帮助或建议将不胜感激:)。

1 个答案:

答案 0 :(得分:0)

()失踪......

$uid = $facebook->getUser();