Created
August 7, 2012 20:39
-
-
Save sergiopvilar/3289083 to your computer and use it in GitHub Desktop.
Autorizaçã de contas do Facebook usando a PHP SDK
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 | |
include("sdk/facebook.php"); | |
define('APP_ID', 'id_do_aplicativo'); | |
define('APP_SECRET', 'app_secret_do_aplicativo'); | |
define('REDIRECT_URI', 'https://url.de/retorno'); | |
define('PERMS', 'publish_stream,status_update,offline_access,create_event,email,user_likes,rsvp_event'); | |
$facebook = new Facebook(array( | |
'appId' => APP_ID, | |
'secret' => APP_SECRET | |
)); | |
// Pega o usuário atual | |
$user = $facebook->getUser(); | |
if ($user) { | |
try { | |
// O usuário está lgoado, recebe os dados dele | |
$user_profile = $facebook->api('/me'); | |
} catch (FacebookApiException $e) { | |
error_log($e); | |
$user = null; | |
} | |
} | |
if ($user) { | |
$logoutUrl = $facebook->getLogoutUrl($params = array('next' => REDIRECT_URI)); | |
} else { | |
$loginUrl = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI, | |
'scope' => PERMS)); | |
} | |
if (!$user): | |
echo('<script>top.location.href="' . $loginUrl . '";</script>'); | |
else: | |
// O usuário está autenticado, seta o token | |
$token = $facebook->getExtendedAccessToken(); | |
$signed_request = $facebook->getSignedRequest(); | |
/* Seu código aqui */ | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment