简体   繁体   中英

CodeIgniter Facebook integration

Is there a Codeigniter library available that allows me to

  • Login users with their Facebook account
  • Import profile data, including interests?

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

Anyone have information about this?

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM