stef
stef

Reputation: 27749

CodeIgniter Facebook integration

Is there a Codeigniter library available that allows me to

This library by Elliot Haughin should cover the login part but I'm less sure about importing profile data.

Anyone have information about this?

Upvotes: 2

Views: 2087

Answers (2)

jondavidjohn
jondavidjohn

Reputation: 62392

The official Facebook PHP SDK actually works fine with Codeigniter.

put base_facebook.php and facebook.php in your libraries directory

create a facebook.php file in your config directory with these contents

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

$config['appId']  = 'YOUR_APP_ID_HERE'; 
$config['secret'] = 'YOUR_APP_SECRET_HERE';

then use it like this

...
$this->load->library('facebook');

//Example usage from sdk example
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $this->facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
    $logoutUrl = $this->facebook->getLogoutUrl();
} else {
    $loginUrl = $this->facebook->getLoginUrl();
}
...

Full writeup here

Upvotes: 10

toopay
toopay

Reputation: 1635

but I'm less sure about importing profile data

Did you mean user profile data? If you want to get full user data (including email, birthday, etc), dont forget to ask user permission for that, in your oauth url, like...

$dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
                    . $fb_app_id . "&redirect_uri=" . urlencode($fb_redirect_url)
                    . "&scope=email,user_about_me,user_activities,user_interests,user_events,user_groups,user_birthday" 
                    . "&state="
                    . $facebook_csrf_state;

Upvotes: 0

Related Questions