brynner
1/27/2013 - 2:26 AM

Login with Facebook. Use the SDK https://github.com/facebook/facebook-php-sdk

Login with Facebook. Use the SDK https://github.com/facebook/facebook-php-sdk

<?php
require_once('base_facebook.php');
require_once('facebook.php');

// Credentials
$fb_app_id = '***************';
$fb_app_secret = '********************************';

$facebook = new Facebook(array('appId'=>$fb_app_id, 'secret'=>$fb_app_secret, 'cookie'=>true));

// Permissions
$allow = 'email,user_status';

$loginurl = $facebook->getLoginUrl(array('scope'=>$allow, 'display'=>'popup'));

$get_fb_user = $facebook->getUser();

// Offline
if (is_null($get_fb_user) or $get_fb_user == 0) {
  
	header("Location: {$loginurl} ");
	exit;
	
// Online
} else {
	
	try {
		
		// Verify
		$facebook->api($get_fb_user);
		
		// Token
		$service_token = $facebook->getAccessToken();
		
		// User Details
		$fql = "SELECT uid, email, username, name, pic_square FROM user WHERE uid = me()";
		$user = $facebook->api(array('method'=>'fql.query', 'query'=>$fql));
		
		echo '
		<ul>
			<li>User id: '.$user['0']['uid'].'</li>
			<li>User email: '.$user['0']['email'].'</li>
			<li>User name: '.$user['0']['name'].'</li>
		</ul>';
		
	} catch (FacebookApiException $e) {
		
		header("Location: {$loginurl} ");
		exit;
	}
	
}
?>