gar*_*hdn 6 php facebook oauth facebook-php-sdk
我一直在寻找解决这个问题的时间,但找不到适合我的方法.当我点击我网站上的"注销"时,用户信息仍然可见,并且仍然显示注销按钮.这是代码:
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxx',
'secret' => 'xxxx',
));
// Get User ID
$user = $facebook->getUser();
var_dump($user);
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($_GET['logout'] == "yes") {
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'http://gno.....ment/index.php');
session_destroy();
header("Location: ".$_SERVER['PHP_SELF']."");
}
if ($user_profile) {
$logoutUrl = $facebook->getLogoutUrl;
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email,publish_stream,user_status',
'canvas' => 1,
'fbconnect' => 0,
'redirect_uri' => 'http://gno.....ment/index.php'));
}
Run Code Online (Sandbox Code Playgroud)
..... .....
<?php if ($user): ?>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
<h3>Your User Object (/me)</h3>
<pre><?php print_r($user_profile); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout of FB</a>
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>
Run Code Online (Sandbox Code Playgroud)
这似乎if ($_GET['logout'] == "yes")可能是我的答案,但我不能让它工作.我不知道logout从哪里获得或在哪里定义?
这似乎是一个常见的问题,但我无法弄清楚.我真的很感激一些帮助.
Tos*_*osh 20
使用PHP SDK进行操作非常简单,文档非常简单.您无需重定向到Facebook.您只需要清除Facebook类设置的会话,在Facebook基类中有一个名为destroySession()的函数.在这里,我正在做这件事.
require_once('libs/facebook.php');
$facebook = new Facebook(array(
'appId' => '1121111110112',
'secret' => 'bcfsaasaaaaaa2b7adsae3a4dd5'
));
if(isset($_GET['action']) && $_GET['action'] === 'logout'){
$facebook->destroySession();
}
Run Code Online (Sandbox Code Playgroud)
$ facebook-> getLogoutUrl()将用户从Facebook中注销.
| 归档时间: |
|
| 查看次数: |
25210 次 |
| 最近记录: |