Home > CakePHP, PHP > Facebook integration

Facebook integration

Following steps to create face book apps In CakePHP :

Step 1 : Create a Facebook A/C

Step 2 : Create an API from the developer face book Apps section

a. https://www.facebook.com/developers/apps.php go to this URL

b. Click the create new App Button

c. Fill the App Display Name and App Namespace text boxes

d. click the Website tab and register your site name

e. Now you get an API Key and security codes.

Step 3 : Collect the Facebook PHP API Script from online

a. Go to https://github.com/facebook/php-sdk

b. Download the PHP Facebook API script

c. Unzip into your local server or demo server

d. Run examples/example.php file, it show how to execute the Facebook API script

Step 4 : Put all library files inside the app/vendors folder, folder name must be facebook/facebook.php, facebook.php file is a class file which have the all functions

Step5 : In AppController you import the facebook classes like App::import(‘Vendor’, ‘facebook/facebook’);

Step 6 : In beforeFilter() function, write the script

$facebook = new Facebook(array(

‘appId’ => ‘263138650385665’,

‘secret’ => ‘9c21ee36a91a81787ff5db8368926ee5’,

));

the appid and secret is which we generate from the step 2.

Step 7 : If user login with facebook then we get the username and email-id and etc from their facebook a/c. Assign these values globally

Step 8 : In users_controller check whether facebook user variable exists or not, if its exists than we create a session name for user authentication

Step 9 : Now we redirect the page into mainpage.

Step 10 : In bas_facebook.php file go to line no 496

function public function getLogoutUrl($params=array(),$url) { }

change the ‘next’ => $this->getCurrentUrl(), into which you want for logout page.

Advertisements
Categories: CakePHP, PHP
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: