Archive

Archive for the ‘CakePHP’ Category

Tweet the content into Twitter

Following steps to create twitter apps In CakePHP :

 

Step 1 : Create a twitter A/C

Step 2 : CURL Must be enabled in your server

Step 3 : Log in to twitter A/C to create an API

a. https://dev.twitter.com/user/login?destination=home

b. Click username on top menu you have one sub menu named My applications

c. Click My application menu

d. Click Create a new application

e. Fill up the application details

f. Callback URL must have .php extenstion

g. Website must be a valid website. we can give our localhost url also

h. Callback URL means after verification of username and password the page redirect into which page

i. click the submit you get the API informations.

j. Under Details->OAuth settings we get Consumer key,Consumer secret and etc.,

 

Step 4 : Go ot Setting Tab in your apps, in Application type you must select the Read and Write or Read, Write and Access direct messages for your apps.

Step 5 : Download the twitter API from online

a. Go to http://www.jaisenmathai.com/articles/twitter-php-sign-in.html and click the link for available for download

b. UnZIP the downloaded package, place the library files into app/vendors/ folder create on folder twitter inside this folder create twitter.php file

c. In twitter.php we include the library files

include ‘EpiCurl.php’;

include ‘EpiOAuth.php’;

include ‘EpiTwitter.php’;

d. In app_controller top we include the following line, App::import(‘Vendor’, ‘twitter/twitter’);

e. Declare these variable as globally

var $consumer_key = ”;

var $consumer_secret = ”;

f. Create an Object for

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

$twitterObj->getAuthenticateUrl() get the login url if user not login than

check whether session $this -> Session -> read(“oauth_token”) exists or not if its not exists than

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

 

Object to connect the twitter API

$twitterObj->setToken($_GET[‘oauth_token’]);

 

twitter return a access token

$token = $twitterObj->getAccessToken();

 

$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);

set the Token into twitter object, the token is valid than we create a session for that token and secret

// save to cookies

if(isset($_GET[‘oauth_token’])){

$this -> Session -> write(“oauth_token”, $token->oauth_token);

$this -> Session -> write(“oauth_token_secret”, $token->oauth_token_secret);

}

 

$twitterInfo= $twitterObj->get_accountVerify_credentials();

 

Finally we get the twiter user A/C credentials

 

Check one more condition for session exists $this -> Session -> read(“oauth_token”). If its exists than, we create a Object for $twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this -> Session -> read(“oauth_token”), $this -> Session -> read(“oauth_token_secret”));

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Now we get the user credentials.

Step 5 : To post content in your twitter A/C the following scripts used to post it

$msg = ‘The message which one you want for it’;

$update_status = $twitterObj->post_statusesUpdate(array(‘status’ => $msg));

 

$temp = $update_status->response;

// Update the status of the twitter object post the conetent and publish it

 

Step 6 : When user can logout we destroy the session.

Categories: CakePHP, PHP

Twitter Integration

Following steps to create twitter apps In CakePHP :

Step1 : Create a twitter A/C

Step2 : CURL Must be enabled in your server

Step3 : Log in to twitter A/C to create an API

a. https://dev.twitter.com/user/login?destination=home

b. Click username on top menu you have one sub menu named My applications

c. Click My application menu

d. Click Create a new application

e. Fill up the application details

f. Callback URL must have .php extenstion

g. Website must be a valid website. we can give our localhost url also

h. Callback URL means after verification of username and password the page redirect into which page

i. click the submit you get the API informations.

j. Under Details->OAuth settings we get Consumer key,Consumer secret and etc.,

Step4 : Download the twitter API from online

a. Go to http://www.jaisenmathai.com/articles/twitter-php-sign-in.html and click the link for available for download

b. UnZIP the downloaded package, place the librarie files into app/vendors/ folder create on folder twitter inside this folder create twitter.php file

c. In twitter.php we include the library files

include ‘EpiCurl.php’;

include ‘EpiOAuth.php’;

include ‘EpiTwitter.php’;

d. In app_controller top we include the following line, App::import(‘Vendor’, ‘twitter/twitter’);

e. Declare these variable as globally

var $consumer_key = ”;

var $consumer_secret = ”;

f. Create an Object for

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

$twitterObj->getAuthenticateUrl() get the login url if user not login than

check whether session $this -> Session -> read(“oauth_token”) exists or not if its not exists than

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

Object to connect the twitter API

$twitterObj->setToken($_GET[‘oauth_token’]);

twitter return a access token

$token = $twitterObj->getAccessToken();

$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);

set the Token into twitter object, the token is valid than we create a session for that token and secret

// save to cookies

if(isset($_GET[‘oauth_token’])){

$this -> Session -> write(“oauth_token”, $token->oauth_token);

$this -> Session -> write(“oauth_token_secret”, $token->oauth_token_secret);

}

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Finally we get the twiter user A/C credentials

Check one more condition for session exists $this -> Session -> read(“oauth_token”). If its exists than, we create a Object for $twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this -> Session -> read(“oauth_token”), $this -> Session -> read(“oauth_token_secret”));

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Now we get the user credentials.

Step 5 : When user can logout we destroy the session.

Categories: CakePHP, PHP

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.

Categories: CakePHP, PHP