Welcome Guest, Not a member yet? Register   Sign In
Problem using facebook-php-sdk
#1

[eluser]ibnclaudius[/eluser]
I'm having problems using the facebook-php-sdk (https://github.com/facebook/facebook-php-sdk). I've download all files inside "src" to my "libraries" folder.

Here's my custom library:

Code:
<?php

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

class My_library
{
    protected $_CI;
    protected $_facebook;

    public function __construct()
    {
        $this->_CI =& get_instance();
    }

    public function facebook_user_id()
    {
        $this->_CI->load->config('bloompit', TRUE);
        $this->_facebook = $this->_CI->config->item('facebook', 'bloompit');
        $this->_CI->load->library('facebook', array(
            'appId' => $this->_facebook['app_id'],
            'secret' => $this->_facebook['secret']
        ));
        return $this->_CI->facebook->getUser();
    }

    public function facebook_user()
    {
        $this->_CI->load->config('bloompit', TRUE);
        $this->_facebook = $this->_CI->config->item('facebook', 'bloompit');
        $this->_CI->load->library('facebook', array(
            'appId' => $this->_facebook['app_id'],
            'secret' => $this->_facebook['secret']
        ));
        try {
            $facebook_user = $this->_CI->facebook->api('/me');
        }
        catch (FacebookApiException $e) {
            log_message('error', $e);
            $facebook_user = NULL;
        }
        return $facebook_user;
    }

    public function facebook_login_url($redirect_uri)
    {
        $this->_CI->load->config('bloompit', TRUE);
        $this->_facebook = $this->_CI->config->item('facebook', 'bloompit');
        $this->_CI->load->helper('url');
        $this->_CI->load->library('facebook', array(
            'appId' => $this->_facebook['app_id'],
            'secret' => $this->_facebook['secret']
        ));
        return $this->_CI->facebook->getLoginUrl(array(
            'scope' => $this->_facebook['scope'],
            'redirect_uri' => $redirect_uri
        ));
    }

    public function facebook_logout_url()
    {
        $this->_CI->load->config('bloompit', TRUE);
        $this->_facebook = $this->_CI->config->item('facebook', 'bloompit');
        $this->_CI->load->helper('url');
        $this->_CI->load->library('facebook', array(
            'appId' => $this->_facebook['app_id'],
            'secret' => $this->_facebook['secret']
        ));
        return $this->_CI->facebook->getLogoutUrl(array(
            'next' => site_url()
        ));
    }
}

The facebook_login_url() seems to be correct, after login the user is redirected back to my site, so I try to get the user id using facebook_user_id(), but is always returning 0. What am I doing wrong?




Theme © iAndrew 2016 - Forum software by © MyBB