Created
February 22, 2011 20:56
-
-
Save maxparm/839372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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