我使用 PHP SDK 并按照示例进行操作。https://github.com/facebook/php-sdk
当我使用 Facebook 登录并授予访问权限时,该页面将重定向到我当前的页面,但 url 包含state
and code
。如何避免显示这些参数?
代码如下:
"oauth.php":
<?php
require 'sdk/facebook.php';
$facebook = new Facebook(array(XXX,XXX));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl($params);
}
?>
+++++++++++++++++++
"index.php":
<?php include 'oauth.php'; ?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<div>
<?php if ($user): ?>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
<?php else: ?>
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php endif ?>
</div>
</body>
</html>