Skip to content

Instantly share code, notes, and snippets.

@jordanandree
Created September 3, 2010 21:49
Show Gist options
  • Save jordanandree/564624 to your computer and use it in GitHub Desktop.
Save jordanandree/564624 to your computer and use it in GitHub Desktop.
<?php
require 'facebook.php';
function facebook_connect(){
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '145062682199939',
'secret' => '',
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
try {
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if ($me) {
$me['logoutUrl'] = $facebook->getLogoutUrl();
$me['uid'] = $facebook->getUser();
} else {
$me['$loginUrl'] = $facebook->getLoginUrl();
}
// set to return so we dont echo data on every call
return $me;
}
$fb_data = facebook_connect();
if($fb_data){
echo $fb_data['name'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment