Welcome Guest, Not a member yet? Register   Sign In
Codeigniter and Facebook SDK
#1

[eluser]ibnclaudius[/eluser]
I'm creating an auth library that will also have login and register with Facebook.

The first time the user login with facebook, he will be redirect to register page, to fill a password, after that, he will always login automatically.

And register will be exactly like the first login.

I download the 3 files inside the folder "src" from the facebook/php-sdk project (https://github.com/facebook/php-sdk) and put it inside application/library, renamed the facebook.php to facebook_lib.php and so changed the class name.

Here's my the facebook part from my custom auth config:
Code:
$config['facebook']['active'] = TRUE;
$config['facebook']['config']['appId'] = 'myappidhere';
$config['facebook']['config']['secret'] = 'mysecrethere';
$config['facebook']['config']['fileUpload'] = TRUE;

and from my custom auth library:
Code:
/**
  * hold all config from facebook
  *
  * @var array
  */
public $facebook = array();

/**
  * __construct
  *
  * @return void
  */
public function __construct()
{
  $this->CI =& get_instance();
  
  $this->CI->load->config('auth', TRUE);
  
  $this->facebook = $this->CI->config->item('facebook', 'auth');
  
  if ($this->facebook['active'] === TRUE)
  {
   $this->CI->load->library('facebook_lib', $this->facebook['config']);
  
   $user = $this->CI->facebook_lib->getUser();
  
   $profile = NULL;
  
   if($user)
   {
    try
    {
     $profile = $this->facebook_lib->api('/me?fields=id,name,link,email');
    }
    catch (FacebookApiException $e)
    {
     error_log($e);
     $user = NULL;
    }
   }
  
   $facebook_data = array(
         'id' => $user,
         'login_url' => $this->CI->facebook_lib->getLoginUrl(array(
           'scope' => 'email,user_birthday,publish_stream',
           'redirect_uri' => $this->site['domain']
          )
         )
       );
  
   $this->CI->session->set_userdata($facebook_data);
  }
}

But it's not working. The session "id" output "0" even if I'm already logged in facebook and the "login_url" output "https://www.facebook.com/dialog/oauth?client_id=360599007314576&redirect_uri=pegaoupassa.com&state=855d833be1c137bf347efd340ccd09e1&scope=email,user_birthday,publish_stream" that give's error when accessing. What am I doing wrong?

Another thing, would you guys recommend I change any other thing?

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB