Return to Snippet

Revision: 42666
at March 8, 2011 17:20 by cdog


Initial Code
<?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);
	  }
	}

?>

Initial URL


Initial Description
default facebook connect script

Initial Title
Facebook Connect Script

Initial Tags
php, facebook

Initial Language
PHP