I have written following script, which checks user's session and displays login/logout links accordingly. Script works, but the problem is, I don't know how to set callback URL, there is no field(or at least I can't find one) at my FB app settings page. Any ideas?
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (开发者_StackOverflow中文版FacebookApiException $e) {
error_log($e);
}
}
?>
<?php if ($me): ?>
<a href="<?php echo $facebook->getLogoutUrl(); ?>">Logout</a>
<?php else: ?>
<a href="<?php echo $facebook->getLoginUrl(array('req_perms'=>"email,publish_stream")); ?>">Login</a>
<?php endif; ?>
The parameter is called "next". So you do it like this:
<a href="<?php echo $facebook->getLoginUrl(array('req_perms'=>"email,publish_stream",'next'=>"welcome.html")); ?>">Login</a>
Change "welcome.html" to wherever you want your user to land on your server after logging in.
IN the facebook php sdk file , about line 418
public function getLoginUrl($params=array()) {
$currentUrl = $this->getCurrentUrl();
return $this->getUrl(
'www',
'login.php',
array_merge(array(
'api_key' => $this->getAppId(),
'cancel_url' => $currentUrl,
'display' => 'page',
'fbconnect' => 1,
'next' => $currentUrl,
'return_session' => 1,
'session_version' => 3,
'v' => '1.0',
), $params)
);
}
and 445
public function getLogoutUrl($params=array()) {
return $this->getUrl(
'www',
'logout.php',
array_merge(array(
'next' => 'http://yoururl.com/?logout=1', // or $currentUrl the same page who make the callback , and destroy session if it.
'access_token' => $this->getAccessToken(),
), $params)
);
}
精彩评论