facebook php sdk进行登录和注销?

facebook php sdk进行登录和注销?,php,facebook,facebook-php-sdk,Php,Facebook,Facebook Php Sdk,我正在尝试使用facebook登录一个网站。为此,我使用了Facebook php SDK的帮助。现在我的代码是这样的 <div id="fb-root"></div> <script type="text/javascript"> //<![CDATA[ window.fbAsyncInit = function() { FB.init({ appId : 'xxxxxxxxxxxxxx', // App ID c

我正在尝试使用facebook登录一个网站。为此,我使用了Facebook php SDK的帮助。现在我的代码是这样的

<div id="fb-root"></div>

<script type="text/javascript">
//<![CDATA[
window.fbAsyncInit = function() {
   FB.init({
     appId      : 'xxxxxxxxxxxxxx', // App ID
     channelURL : '', // Channel File, not required so leave empty
     status     : true, // check login status
     cookie     : true, // enable cookies to allow the server to access the session
     oauth      : true, // enable OAuth 2.0
     xfbml      : false  // parse XFBML
   });
};
// logs the user in the application and facebook
function login(){
FB.getLoginStatus(function(r){
     if(r.status === 'connected'){
            window.location.href = 'fbconnect.php';
     }else{
        FB.login(function(response) {
                if(response.authResponse) {
              //if (response.perms)
                    window.location.href = 'fbconnect.php';
            } else {
              // user is not logged in
            }
     },{scope:'email'}); // which data to access from user profile
 }
});
}
// Load the SDK Asynchronously
(function() {
   var e = document.createElement('script'); e.async = true;
   e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
   document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>
<?php
require_once 'src/facebook.php'; //include the facebook php sdk
$facebook = new Facebook(array(
        'appId'  => 'xxxxxxxxxxxxxx',    //app id
        'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // app secret
));
$user = $facebook->getUser();
if ($user) { // check if current user is authenticated
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');  //get current user's profile information using open graph
            }
         catch(Exception $e){}
}
?>
<a href='#' onclick='login();'>Facebook Login</a>

//
现在有了这段代码,我可以轻松登录了。但在这之后,我还需要两样东西

  • 登录后进行注销。那么我如何在这里创建注销功能呢 因此,当用户单击注销时,他将同时从这两个站点注销 facebook和该网站在同一时间
  • 如何在登录后获取用户信息,如他的姓名、电子邮件id等

有人能告诉我怎么做吗?我只是facebook应用程序的新手。因此,任何帮助和建议都是值得赞赏的。感谢获取注销URL,您可以尝试以下操作:

$fbUserId = $facebook->getUser();

if ($fbUserId) {
    $host = $_SERVER['HTTP_HOST'];
    $params = array('next' => "http://{$host}/project/page.php");
    $logoutUrl = $facebook->getLogoutUrl($params);
}
要获取用户详细信息,可以尝试以下操作

try {
    $user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
    return false;
}

return $user_profile;