简体   繁体   中英

CodeIgniter Facebook API getuser always 0

I know this is a duplicate, however, I've tried pretty much everything suggested in the other questions.

I'm currently getting a redirect loop because getUser is always returning 0, even after approving the app.

Code:

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);
}

Here is the screenshot of my settings page for this App.

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

Sometimes it does work, but most of the time it doesn't.

Found the solution here: http://www.galalaly.me/index.php/2012/04/using-facebook-php-sdk-3-with-codeigniter-2-1/

Had to add:

    parse_str($_SERVER['QUERY_STRING'], $_REQUEST);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM