FB.logout不适合我

时间:2014-02-22 09:45:12

标签: php facebook

我正在尝试将facebook登录添加到我的网站中。我遇到的问题是当我点击退出链接时它没有给出任何回复。我知道此类问题之前已经问过,但我搜索了很多我的解决方案,但还没有找到,所以我终于带着希望来到这里。请帮忙。

我试过的代码就在这里......“index.php”

<?php
error_reporting(0);
include 'library.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Vector facebook login</title>
<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({
    appId      : 'XXXXXXXXXXXXX', // replace your app id here
    channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', 
    status     : true, 
    cookie     : true, 
    xfbml      : true  
    });
};
(function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
}(document));

function FBLogin(){
    FB.login(function(response){
        if(response.authResponse){
            window.location.href = "actions.php?action=fblogin";
        }
    }, {scope: 'email,user_likes'});
}
</script>
<style>
body{
    font-family:Arial;
    color:#333;
    font-size:14px;
}
</style>
</head>

<body>

<img src="facebook-connect.png" alt="Fb Connect" title="Login with facebook" onclick="FBLogin();"/>
</body>
</html>

这是另一个文件“actions.php”

<?php
include 'library.php';
/*
CREATE TABLE `demo`.`fblogin` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`fb_id` INT( 20 ) NOT NULL ,
`name` VARCHAR( 300 ) NOT NULL ,
`email` VARCHAR( 300 ) NOT NULL ,
`image` VARCHAR( 600 ) NOT NULL,
`postdate` DATETIME NOT NULL
) ENGINE = InnoDB;
*/
$action = $_REQUEST["action"];
switch($action){
    case "fblogin":
    include 'facebook.php';
    $appid      = "XXXXXXXXXXXX";
    $appsecret  = "XXXXXXXXXXXXXXXXXXXX";
    $facebook   = new Facebook(array(
        'appId' => $appid,
        'secret' => $appsecret,
        'cookie' => TRUE,
    ));
    $fbuser = $facebook->getUser();
    if ($fbuser) {
        try {
            $user_profile = $facebook->api('/me');
        }
        catch (Exception $e) {
            echo $e->getMessage();
            exit();
        }
        $user_fbid  = $fbuser;
        $user_email = $user_profile["email"];
        $user_fnmae = $user_profile["first_name"];
        $user_image = "https://graph.facebook.com/".$user_fbid."/picture?type=large";
        $check_select = mysql_num_rows(mysql_query("SELECT * FROM `fblogin` WHERE email = '$user_email'"));
        if($check_select < 1){
            mysql_query("INSERT INTO `fblogin` (fb_id, name, email, image, postdate) VALUES ('$user_fbid', '$user_fnmae', '$user_email', '$user_image', '$now')");
        }
    }
    break;
}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Asif18 tutorial about facebook login for mywebsite using php sdk</title>
<script id="facebook-jssdk" async="" src="//connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({
    appId      : 'XXXXXXXXXXXXXXXXX', // replace your app id here
    channelUrl : '', 
    status     : true, 
    cookie     : true, 
    xfbml      : true  
    });
};
(function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
}(document));

function FBLogout(){

    FB.logout(function(response){
        alert("inner");

        window.location.href = "index.php";
    });
}
</script>
<style>
body{
    font-family:Arial;
    color:#333;
    font-size:14px;
}
.mytable{
    margin:0 auto;
    width:600px;
    border:2px dashed #17A3F7;
}
a{
    color:#0C92BE;
    cursor:pointer;
}
</style>
</head>

<body>

<h3>here is the user details, for more details </h3>
<table class="mytable">
<tr>
    <td colspan="2" align="left"><h2>Hi <?php echo $user_fnmae; ?>,</h2><a onClick="FBLogout();">Logout</a></td>
</tr>
<tr>
    <td><b>Fb id:<?php echo $user_fbid; ?></b></td>
    <td valign="top" rowspan="2"><img src="<?php echo $user_image; ?>" height="100"/></td>
</tr>
<tr>
    <td><b>Email:<?php echo $user_email; ?></b></td>
</tr>
</table>
</body>
</html>

0 个答案:

没有答案