Facebook GetUser()返回0而不更改我的代码

时间:2013-10-02 09:02:15

标签: facebook

我在我的网站上实现了用户登录。到目前为止,这一点很好用。当我尝试使用Facebook帐户登录时,我总是从GetUser()获得0。我尝试使用不同的Web浏览器,将PHP SDK更新到最新版本,但仍然无法正常工作。任何线索?

$facebook = new Facebook(array(
    'appId'  => 'my APP ID',
    'secret' => 'my Secret',
    'cookie' => false, // enable optional cookie support
  ));

  $user = $facebook->getUser();
  if ($user) {
    try {
      // Proceed knowing you have a logged in user who's authenticated.
      $user_profile = $facebook->api('/me');
      $likes = $facebook->api("/me/likes/ID HIDDEN");
      if (!isset($_SESSION['prijavljen'])) { 
        $_SESSION['prijavljen'] = True;
      }
      if (!empty($likes['data'])) $fblike = true; else $fblike = false;    
    } 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();
    $logoutUrl = $facebook->getLogoutUrl(array( 'next' => 'my URL'));
    } else {
    $params = array('scope' => 'email,user_birthday,user_education_history,user_hometown,user_likes', 'redirect_uri' => curPageURL());
    $loginUrl = $facebook->getLoginUrl($params);  
  }

1 个答案:

答案 0 :(得分:0)

您服务器上的PHP版本最近是否已更新?您可以尝试this fix并查看getUser()功能是否再次开始为您效果。