Sep
21

In Facebook’s Single Sign-on using JavaScript SDK , i discussed how single-sign on works. Now, I will discuss how to use the signed cookie and curl in fetching the active user’s data.

Parsing the signed cookie
Below is a script that is available in the facebook developer’s page. It parses the signed cookie saved on your registered site having the fbs_APP_ID format.

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str( trim( $_COOKIE['fbs_' . $app_id], '\\"' ), $args );
  ksort( $args );
  $payload = '';
  foreach ( $args as $key => $value ) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if ( md5( $payload . $application_secret ) != $args['sig'] ) {
    return null;
  }
  return $args;
}

The most important part of the cookie that we will use is the access_token. If the token is incorrect the Graph API will give a OAuthException error type.
Continue Reading →

Sep
18

Using JavaScript SDK is an easy way to implement login and sign up using OAuth 2.0 protocol.

How does it work?
The JavaScript SDK saves the credentials for the active facebook user in a cookie on your registered site’s domain. Once there is a cookie present, you can fetch the active facebook user’s information in facebook and use it in your code.

Session Detection
The SDK automatically detects if there is a cookie present in your registered site. If there is, it will automatically login the currrent user without the need to click the facebook login button.

Continue Reading →

Sep
6

Virtual fields in cakephp are used as an alias in sql expressions. Alias is used to give a column a different name.

Example, to concatenate fields,

class Applicant extends AppModel {
    var $name = 'Applicant';
    var $virtualFields = array( 'name' => "CONCAT(Applicant.firstname, ' ', Applicant.lastname)" );
}

To access the virtual field

$this->Applicant->find( 'first', array( 'fields' => array( 'name' ) ) );
Jun
4
Mac

Any unsaved application data will not be saved once an application was forced to quit. Do it only if necessary.

When to force quit an application? Only when its unresponsive and cannot be quit in a usual manner.

Continue Reading →

Jun
4

Scrolling to the top and bottom is very easy in mootools. Check out the code below.

window.addEvent('domready', function(){

	var myFx = new Fx.Scroll(window);

	$('bottom').addEvent('click', function(e){
		e.stop();
		myFx.toBottom();
	});

	$('top').addEvent('click', function(e){
		e.stop();
		myFx.toTop();
	});

});

Lines 5-8 lets you scroll to the bottom of the page. While lines 10-13 lets you scroll to the top of the page. Easy huh?

Note: Fx.Scroll plugin must be included. Get it at Mootools More Builder.

Check out the demo

© 2012 · Karl Sheen Blog · Sitemap · Proudly powered by Wordpress and Twitter Bootstrap · Icons by Glyphicons