• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Facebook-PHP-SDK

#1
[eluser]ibnclaudius[/eluser]
I'm developing a simple authentication trough Codeigniter 2.1.2 and Facebook-PHP-SDK 3.1.1, but I have no idea why it's now working.

I've downloaded all files from the src folder (https://github.com/facebook/facebook-php...master/src) into my libraries.

The login seems to be working, but when the user is redirected back to my website, the Facebook getUser() function always returns 0!

Code:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Bloompit extends CI_Controller
{
    public $user;

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('session');
        $this->load->library('facebook', array(
            'appId' => '149275358530064',
            'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxx'
        ));
        $this->load->model('bloompit_model');
        $this->user = $this->session->userdata('user');
    }

    public function index()
    {
        $data['title'] = 'Bloompit';
        $data['page'] = 'home';
        $this->load->view('view', $data);
    }

    public function login()
    {
        if ($this->user) {
            redirect(site_url(), 'location');
        } elseif ($this->facebook->getUser()) {
            try {
                $facebook_user = $this->facebook->api('/me');
                $this->session->set_userdata('user', array(
                    'name' => $facebook_user['name']
                ));
            } catch (FacebookApiException $e) {
                log_message('error', $e);
                redirect($this->facebook->getLoginUrl(array(
                    'scope' => 'email',
                    'redirect_uri' => site_url('login')
                )), 'location');
            }
        } else {
            $data['facebook_login_url'] = $this->facebook->getLoginUrl(array(
                'scope' => 'email',
                'redirect_uri' => site_url('login')
            ));
            $data['title'] = 'Entrar';
            $data['page'] = 'login';
            $this->load->view('view', $data);
        }
    }

    public function logout() {
        session_destroy();
        redirect($this->facebook->getLogoutUrl(array(
            'next' => site_url()
        )), 'location');
    }
}

#2
[eluser]Jason Hamilton-Mascioli[/eluser]
Please try my facebook codeigniter starter kit and maybe it may help figure out your issue ... https://github.com/hamiltonmascioli/face...xample.php

#3
[eluser]Jason Hamilton-Mascioli[/eluser]
For your specific issue try reading ... http://stackoverflow.com/questions/70476...login-does

This has also worked ...

Code:
adding FB.api('/me', function(response) { to the login




Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.