Facebook登录Codeigniter突然停止工作

时间:2012-11-04 15:18:17

标签: facebook codeigniter

我正在使用Facebook与Codeigniter,并且工作正常 但突然停止工作,facebook改变了什么

facebook功能

public function takofacebook($page = TRUE, $name = TRUE) {

    if (isset($page) and (($page != TRUE) or ($page != 1)) and isset($name)) {
        $data['page'] = $page;
        $data['name'] = $name;
    }

    $this -> load -> library('fb');
    if (!$this -> fb -> is_connected()) {
        redirect($this -> fb -> login_url(current_url()));
    }

    $fb_user = $this -> fb -> client -> api('/me');

    if (empty($fb_user)) {
        $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
        $this -> session -> set_flashdata('register_error', $error);
    } else {
        $this -> user -> set_facebook_id($fb_user['id']);
        $user = $this -> user -> get_by_facebook();
        if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {

            //TODO: Make things a bit more secure here
            //Login & Redirect home

            $this -> _login($user -> id, 'facebook');
            $this -> load -> view('users/redirect_home2', $data);
            return;
        }
    }
    //Go to the registeration page
    $this -> load -> view('users/redirect2', array('method' => 'facebook'));
}

/**
 * Logs user in with facebook
 */

 //tako facebook
public function zangafacebook() {



    $this -> load -> library('fb');
    if (!$this -> fb -> is_connected()) {
        redirect($this -> fb -> login_url(current_url()));
    }

    $fb_user = $this -> fb -> client -> api('/me');

    if (empty($fb_user)) {
        $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
        $this -> session -> set_flashdata('register_error', $error);
    } else {
        $this -> user -> set_facebook_id($fb_user['id']);
        $user = $this -> user -> get_by_facebook();
        if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {

            //TODO: Make things a bit more secure here
            //Login & Redirect home

            $this -> _login($user -> id, 'facebook');
            $this -> load -> view('users/redirect_home3');
            return;
        }
    }
    //Go to the registeration page
    $this -> load -> view('users/redirect3', array('method' => 'facebook'));
}

1 个答案:

答案 0 :(得分:1)

我在我的CodeIgniter网站上测试了来自Facebook的官方php sdk,它运行正常。 $ fb_user是空的吗?错误在哪里?您使用Facebook官方PHP SDK吗?有很多变量可以找出这里出了什么问题。 就像ifaour建议的那样,如果您还没有使用官方的php sdk:https://github.com/facebook/facebook-php-sdk/tree/master/src

删除库目录中的文件并正常调用

$this -> load -> library('facebook');

然后你就可以得到这样的facebook数据:

$fb_user = $this -> facebook -> api('/me');

我再也不确定你的错误在哪里,你在这里错过了一个参数吗?

$ user = $ this - >用户 - > get_by_facebook(的 $ fb_user [ 'ID'] );

这就是我在我的网站上所做的一切,它运作得很好。这也有一个好处,如果Facebook确实改变了你需要下载的新SDK,你的代码应该保持不变。