PHP – Facebook – Connect Script

The given PHP example is the default facebook connect script.

Code Example:
<?php
	require 'src/facebook.php'; // download from github facebook php sdk
	
	// Create our Application instance (replace this with your appId and secret).
	$facebook = new Facebook(array(
	  'appId'  => 'YOUR_APP_ID',
	  'secret' => 'YOU_SECRET_KEY',
	  'cookie' => true,
	));
	
	// We may or may not have this data based on a $_GET or $_COOKIE based session.
	//
	// If we get a session here, it means we found a correctly signed session using
	// the Application Secret only Facebook and the Application know. We dont know
	// if it is still valid until we make an API call using the session. A session
	// can become invalid if it has already expired (should not be getting the
	// session back in this case) or if the user logged out of Facebook.
	$session = $facebook->getSession();
	
	$fbinfo = null;
	// Session based API call.
	if ($session) {
	  try {
		$fbid = $facebook->getUser();
		$fbinfo = $facebook->api('/me');
		//print_r($fbinfo);
	  } catch (FacebookApiException $e) {
		error_log($e);
	  }
	}
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *