Sie sind auf Seite 1von 4

Step by Step to develop a facebook Application using Codeigniter

Codeigniter is a PHP framework.

Steps On Facebook Side

1. First you need to log in to the Facebook Developer application:Go to the


Facebook Developer App After following the link, click “Allow” to let the
Developer application access your profile.
2. Begin setting up a new application. Go to the Developer application and click
“Set Up New Application”. Give your application a name, check to accept the
Terms of Service, then click Submit. You'll see some basic information about
your application, including:
a. Your API key: this key identifies your application to Facebook. You
pass it with all your API calls.
b. Your application secret: Facebook uses this key to authenticate the
requests you make. As you can tell by its name, you should never
share this key with anyone.
3. Now we need to configure a few more settings before we can get into the
code. Click "Edit Settings". Notice that the support and contact email
addresses are pre-populated with the email address associated with your
Facebook account.
4. Enter a callback URL. This is the address where your application lives on your
server, or the server where the application is being hosted.
5. Enter a canvas page URL. A canvas page is the address where your
application lives on Facebook. When users access your application on
Facebook, they're taken to your canvas page. It's a good idea to use your
application name or something similar. It must be at least 7 characters long
and include only letters, dashes and underscores.
6. You want users to be able to put your application on their profiles, so select
“Yes” at “Can your application be added on Facebook?”
7. Believe it or not, this is all we really need to get a simple application ready to
go. Click "Save and continue".
Steps On Your Server Side

1. Install Appache and MySql

2. Download and copy the Codeigniter from http://codeigniter.com/ in your root


directory.

3. Now Setup the CodeIgniter configuration according as described below:

In application/config/config.php

a. set config[‘base_url’] to like ‘http://apps.facebook.com/your-app-name/’.

b. set $config['permitted_uri_chars'] from 'a-z 0-9~%.:_\-' to '&=a-z


0-9~%.:_\-'

c. set $config['uri_protocol'] from AUTO to PATH_INFO.

4. We have to set a default controller i.e. the controller file which will run first. Assume that we
have a controller named “welcome” . so set the default controller in
application/config/routes.php by setting $route['default_controller'] =’welcome’ .

a. Download the facebook client libaray from


http://developers.facebook.com/resources.php , You would see a link
named ‘PHP Client Libraries’ there, use that linke to download the
library.

b. Unzip the package and open it there are two folder in it “php” and
“footprints” open the “php” folder there are three files and one folder,
just rename the facebook.php to facebook_pi.php and place all
these contents to application/plugins, if plugins folder is not there,
just create it.

c. Create a library in application/libraries , let’s say named


‘Initializer’ having code as following:

class Initializer
{
var $__fbApiKey = 'Your App Id';
var $__fbSecret = 'Your App Secret';
var $CI;
function Initializer()
{
$CI =&get_instance();
$CI->load->plugin('facebook');
$GLOBALS['facebook_config']['debug'] = NULL;
$this->facebook = new Facebook($this->__fbApiKey,
$this->__fbSecret);
$this->user = $this->facebook->require_login();
}
}

5. Include these lines in each of your controller, before the controller


constructor defination.

var $facebook;
var $user;
var $initializer;

6. Add the following code in each controller constructor defination.

$this->load->library('initializer');
$this->initializer = new initializer();
$this->facebook = $this->initializer->facebook;
$this->user = $this->initializer->user;

7. Now just use the server url which was set in config.php and the application
can be seen on facebook, Whatever you would have written in your default
controller named ‘ welcome ‘ would start executing and so on.

Das könnte Ihnen auch gefallen