2014-11-24 46 views
0

我使用此代碼(codeigniter-facebook-php-sdk-v4)將我的控制器連接到Facebook登錄。 Mycontroller在Facebook登錄CodeIgniter後頁面不重定向

public function index() { 
    //load views 
    $this->load->view('pages/header'); 
    $this->load->view('pages/index'); //contains a href of mycontroller/facebook_login 
    $this->load->view('pages/footer'); 
} 

public function facebook_login() { 
    $fb_data = $this->lib_facebook->facebook(); 

    if (isset($fb_data['me'])) { 
     //save fb user data 
    } 
} 

數據保存後,瀏覽器仍然是mycontroller/facebook_login頁。我想讓它重定向到index頁面。

回答

0

的Facebook \ FacebookRedirectLoginHelper

如果你的Web應用程序在後端使用Facebook的登錄,您將需要 重定向訪問者到Facebook的一個URL來啓動登錄 請求。 Facebook然後將用戶重定向到您的應用回調URL, 提供會話數據。這個輔助類將爲您生成登錄URL ,並且可以處理和驗證來自Facebook的數據, 返回FacebookSession成功。

記得當你設置你的回調URL嗎?是的,在做出請求之前請改變它。

// change the url before you make the request 
$desired_url = 'url_desired'; // set the url you want the user to be redirected after logging in 
$helper = new FacebookRedirectLoginHelper($desired_url); 

然後你就可以簡單地使用

echo '<a href="' . $helper->getLoginUrl() . '">Login with Facebook</a>'; 
+0

太好了!這工作。謝謝。另外,我可以擺脫URL參數?在URL中? – u134211 2014-11-24 20:56:11

+0

不,你不能,我試過並搜索過,它似乎是一個Facebook的API錯誤。 – 2014-11-24 20:58:11

+0

那麼,有沒有其他解決方法可以將其刪除? – u134211 2014-11-24 21:00:07