2012-10-08 34 views
0

我知道这是重复的,但是,我尝试了几乎所有在其他问题中提出的建议。CodeIgniter Facebook API getuser始终为0

我目前得到一个重定向循环,因为getUser总是返回0,即使在批准应用程序之后。

代码:

public function auth() { 
    $user = $this->facebook->getUser(); 

    if ($user) { 
     $user = $this->facebook->api('/me'); 
     if (!$this->Users->getByID($user["id"])) { 
      $this->data->needsRegister = true; 
     } else { 
      $toSetInSessions = new stdClass(); 
      $toSetInSessions->authed = 1; 
      $dbUser = $this->Users->getByID($user["id"]); 
      foreach ($dbUser as $key => $value) { 
       $toSetInSessions->user->$key = $value; 
      } 
      $this->session->set_userdata($toSetInSessions); 
      redirect("/"); 
     } 
    } else { 
     $params = array('scope' => 'email,read_friendlists'); 
     if ($_SERVER['HTTP_USER_AGENT'] != "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") { 
      redirect($this->facebook->getLoginUrl($params)); 
     } 
    } 

    $this->load->view('header', $this->data); 
    $this->load->view('auth', $this->data); 
    $this->load->view('footer', $this->data); 
} 

这里是我的设置为这个应用程序页面的截图。

https://dl.dropbox.com/u/6647629/facebookapp.png

有时它的工作,但大部分时间都没有。

回答