Skip to content

Instantly share code, notes, and snippets.

@maxparm
Created February 22, 2011 20:56
Show Gist options
  • Save maxparm/839372 to your computer and use it in GitHub Desktop.
Save maxparm/839372 to your computer and use it in GitHub Desktop.
<?php
class Me_Controller_Plugin_Facebook extends Zend_Controller_Plugin_Abstract
{
public function preDispatch($request)
{
//Initialize Facebook Api
require(APPLICATION_PATH.'/../library/facebook.php');
$facebook = new Facebook(array(
'appId' => FACEBOOK_APIKEY,
'secret' => FACEBOOK_APISECRET,
'cookie' => true,
));
//Get facebook session of user
$session = $facebook->getSession();
//User connected
if($session) {
$fbUserId = $facebook->getUser();
$me = $facebook->api('/me');
$access_token = $session['access_token'];
}
//User not connected so redirected to facebook login url
else {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl($facebook->getLoginUrl(array()));
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment