使用PHP退出Facebook

时间:2018-11-13 14:29:29

标签: facebook facebook-php-sdk facebook-login

我正在使用Facebook的PHP SDK将用户登录到我的网站。 现在,当我单击注销按钮时,它将成功清除会话。当他再次单击“使用Facebook登录”按钮时,他将使用注销前使用的相同Facebook帐户自动登录到我的网站,而不显示登录页面。

<?php
    session_start();  
    /*
        echo "before logout.</BR></BR>"; 
        echo 'id: ' . $_SESSION['id']."</BR></BR>";
    */

    require_once 'Facebook/autoload.php';
    require_once 'Facebook/Facebook.php';

    $config = array();
    $config['appId'] = 'My Appid';
    $config['secret'] = 'My Secret';
    $config['fileUpload'] = false;

   $fb = new Facebook\Facebook([
        'app_id' => 'My Appid', // Replace {app-id} with your app id
        'app_secret' => 'My Secret',
        'default_graph_version' => 'v3.2',
    ]);

    //$facebook = new Facebook($config);
    //$token = $fb->getAccessToken();

    //$accessToken = $fb->getAccessToken(); // Not working - Error showing - undefined method

    //echo $_SESSION['fb_access_token']; - This contains some long access token

    unset($_SESSION['id']);
    //echo $accessToken;
    /*
        echo "after logout.</BR></BR>"; 
        echo 'id : '. $_SESSION['id']."</BR></BR>";
    */
    //$url = 'https://www.facebook.com/logout.php?next=https://rocketevent.in&access_token='.$_SESSION['fb_access_token']; - going to facebook page, not returning back 
    //echo $url;
    session_destroy();
    $fb->getLogoutUrl();
    //header('Location: '.$url);
   //header("Location: ../../index.php");
?>

1 个答案:

答案 0 :(得分:0)

您应提供“ app_id”和“ app_secret”。您可以从https://developers.facebook.com

获取这些内容