Facebook is getting bigger and more of us want to code with API of Facebook. If you integrate with CodeIgniter and Facebook, you have two choice: one of them is Junal’s approach and another way is Elliot’s way. My approach is quite different then.
Firstly, I create a config file which name is facebook.php in application/config directory as coded below. You shall be changed these sentences as your case.
<?php
$config['facebook_api_key'] = 'your_api_key';
$config['facebook_secret_key'] = 'your_secret_key';
Secondly, I downloaded Facebook client library form developer center. These files shall be stored on application/plugins directory (if there is not folder named plugins then you must create it) and renamed my facebook.php file to facebook_pi.php.
These steps are almost same with Junal’s way. After that I create MY_Controller.php file on application/library directory as coded below:
<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
class Facebook_Controller extends Controller {
public $facebook;
public $user;
function Facebook_Controller()
{
parent::Controller();
$this->load->config('facebook');
$this->__fbApiKey = $this->config->item('facebook_api_key');
$this->__fbSecret = $this->config->item('facebook_secret_key');
$this->load->plugin('facebook');
// Prevent the 'Undefined index: facebook_config' notice from being thrown.
$GLOBALS['facebook_config']['debug'] = NULL;
// Create a Facebook client API object.
$this->facebook = new Facebook($this->__fbApiKey, $this->__fbSecret);
$this->user = $this->facebook->require_login();
}
}
Then, create a default controller file which name is welcome.php on application/controller directory :
<?php
class Welcome extends Facebook_Controller {
function Welcome ()
{
parent::Facebook_Controller();
}
function index()
{
// Retrieve the user's friends and pass them to the view.
$data['friends'] = $this->facebook->api_client->friends_get();
$this->load->view('welcome_message' ,$data);
}
}
Finally, here is my welcome_message.php file which is stored on application/view directory.
<style type="text/css">
.img {
float: left;
padding : 10px 0px 0px 10px;
width:50px;
overflow: visible;
}
.name {
padding-top: 0px;
text-align: center;
}
.container
{
padding-left:18px;
}
</style>
<div class="container">
<?php
foreach ($friends as $id)
{
?>
<div class='img'>
<fb:profile-pic uid='<?=$id?>' firstnameonly = 'true' linked='true' size='square'/>
<div class='name'>
<fb:name uid='<?=$id?>' firstnameonly = 'true' capitalize='true' useyou = 'false'/>
</fb></div>
</fb></div>
<?php
}
?>
</div>
This is my way ![]()
