1

i am using the facebook php sdk in conjunction with codeigniter. the problem i have now is that i seem to be unable to get the user_id via get_user() it will always return 0. this is my code:

<?php

class Facebook_model extends CI_Model {

   public function __construct() {
        parent::__construct();
        $config = array(
            'appId' => '....',
            'secret' => '...',
            'fileUpload' => true
        );
    $this->load->library('facebook', $config);
    $user = $this->facebook->getUser();

    $profile = null;

    if ($user) {
        try {
            $profile = $this->facebook->api('/me?fields=id,name,link,email');
        } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
        }
    }
    $fb_data = array(
        'me' => $profile,
        'uid' => $user,
        'loginUrl' => $this->facebook->getLoginUrl(
                array(
                    'scope' => 'email,user_birthday,publish_stream'// URL where you want to redirect your users after a successful login
                )
        ),
        'logoutUrl' => $this->facebook->getLogoutUrl()
    );
    $this->session->set_userdata('fb_data', $fb_data);
}

}

i read somewhere it could be a problem with cookies and codeigniter but i can't figure ou how to solve this issue

  • I think your appID and secret are not being read, try hard-coding the $config array inside the facebook library constructor. – flopperJ Jun 14 '12 at 22:52
  • See if [This](http://stackoverflow.com/questions/10598132/facebook-user-id-returning-0-always/10636678#10636678) can help you – MSUH Jun 15 '12 at 06:34

1 Answers1

0

configure your facebook configuration file as below

$facebook = new Facebook('keep your facebook config file here');
$my_details = $facebook->api('/me');

now the array $my_details will give you the complete details of your fb application along with the user id

kumar
  • 1,796
  • 2
  • 15
  • 37