Welcome Guest, Not a member yet? Register   Sign In
Facebook Controller
#1

[eluser]Fatih[/eluser]
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.

Code:
<?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:

Code:
<?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 :

Code:
<?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.

Code:
<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">
&lt;?php
foreach ($friends as $id)
{
?&gt;
<div class='img'>
    <fb:profile-pic uid='&lt;?=$id?&gt;' firstnameonly = 'true' linked='true' size='square'/>
<div class='name'>
        <fb:name uid='&lt;?=$id?&gt;' firstnameonly = 'true' capitalize='true'  useyou = 'false'/>
    </fb></div>
</fb></div>
&lt;?php
}
?&gt;
</div>

This is my way Smile


Messages In This Thread
Facebook Controller - by El Forum - 06-17-2009, 01:52 AM
Facebook Controller - by El Forum - 06-17-2009, 01:05 PM
Facebook Controller - by El Forum - 07-22-2009, 08:02 AM
Facebook Controller - by El Forum - 07-22-2009, 08:14 AM
Facebook Controller - by El Forum - 07-22-2009, 03:16 PM
Facebook Controller - by El Forum - 07-22-2009, 11:47 PM
Facebook Controller - by El Forum - 07-23-2009, 06:34 AM
Facebook Controller - by El Forum - 07-23-2009, 06:59 AM
Facebook Controller - by El Forum - 07-26-2009, 10:31 AM
Facebook Controller - by El Forum - 07-26-2009, 12:49 PM
Facebook Controller - by El Forum - 07-26-2009, 02:48 PM
Facebook Controller - by El Forum - 07-26-2009, 02:50 PM
Facebook Controller - by El Forum - 07-26-2009, 03:02 PM
Facebook Controller - by El Forum - 07-26-2009, 11:27 PM
Facebook Controller - by El Forum - 07-26-2009, 11:36 PM
Facebook Controller - by El Forum - 07-27-2009, 02:22 AM
Facebook Controller - by El Forum - 07-28-2009, 12:35 PM
Facebook Controller - by El Forum - 07-28-2009, 01:36 PM
Facebook Controller - by El Forum - 07-28-2009, 02:34 PM
Facebook Controller - by El Forum - 07-28-2009, 11:37 PM
Facebook Controller - by El Forum - 07-29-2009, 11:58 AM
Facebook Controller - by El Forum - 02-25-2010, 12:15 AM
Facebook Controller - by El Forum - 02-25-2010, 12:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB