2014-02-26 150 views
1

我在我的web應用程序上使用了facebook javascript sdk。我正在使用圖形API來登錄我的應用程序。當我從我的應用程序註銷時,我的應用程序已註銷,我的Facebook帳戶也是註銷。如何僅註銷我的FB應用程序而不是我的Facebook帳戶?

如何只註銷我的應用程序不是我的Facebook帳戶?

如果有人找到解決方案,請幫助我。

代碼:

<script type="text/javascript">  

    var button; 
    var userInfo; 

    window.fbAsyncInit = function() { 
     FB.init({ appId: '########', 
      status: true, 
      cookie: true, 
      xfbml: true, 
      oauth: true}); 

     showLoader(true); 

     function updateButton(response) { 
      button  = document.getElementById('fb-auth'); 
      userInfo  = document.getElementById('user-info'); 
      userdata = document.getElementById('user-data'); 
      if (response.authResponse) { 
       //user is already logged in and connected 
       FB.api('/me', function(info) { 
        login(response, info); 
       }); 

       button.onclick = function() { 
        FB.logout(function(response) { 
         logout(response); 
        }); 
       }; 
      } else { 
       //user is not connected to your app or logged out 
       button.innerHTML = 'Login'; 
       button.onclick = function() { 
        showLoader(true); 
        FB.login(function(response) { 
         if (response.authResponse) { 
          FB.api('/me', function(info) { 
           login(response, info); 
          });  
         } else { 
          //user cancelled login or did not grant authorization 
          showLoader(false); 
         } 
        },         {scope:'email,user_birthday,status_update,publish_stream,user_about_me'}); 
       } 
      } 
     } 

     // run once with current status and whenever the status changes 
     FB.getLoginStatus(updateButton); 
     FB.Event.subscribe('auth.statusChange', updateButton); 
    }; 
    (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); 
    }()); 


    function login(response, info){ 
     if (response.authResponse) { 
      var accessToken         = response.authResponse.accessToken; 

      userInfo.innerHTML        = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name 
                  + "<br /> Your Access Token: " + accessToken; 


    button.innerHTML        = 'Logout'; 
      showLoader(false); 
      document.getElementById('other').style.display = "block"; 

     } 
    } 

    function logout(response){ 
     userInfo.innerHTML        = ""; 
     document.getElementById('debug').innerHTML  = ""; 
     document.getElementById('other').style.display = "none"; 
     showLoader(false); 
    } 

    //stream publish method 
    function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){ 
     showLoader(true); 
     FB.ui(
     { 
      method: 'stream.publish', 
      message: '', 
      attachment: { 
       name: name, 
       caption: '', 
       description: (description), 
       href: hrefLink 
      }, 
      action_links: [ 
       { text: hrefTitle, href: hrefLink } 
      ], 
      user_prompt_message: userPrompt 
     }, 
     function(response) { 
      showLoader(false); 
     }); 

    } 
    function showStream(){ 
     FB.api('/me', function(response) { 
      //console.log(response.id); 
      streamPublish(); 
     }); 
    }   

    function share(){ 
     showLoader(true); 
     var share = { 
      method: 'stream.share', 
      u: 'http://www.appovative.com/' 
     }; 

     FB.ui(share, function(response) { 
      showLoader(false); 
      console.log(response); 
     }); 
    } 



    function setStatus(){ 
     showLoader(true); 

     status1 = document.getElementById('status').value; 
     FB.api(
      { 
      method: 'status.set', 
      status: status1 
      }, 
      function(response) { 
      if (response == 0){ 
       alert('Your facebook status not updated. Give Status Update  Permission.'); 
      } 
      else{ 
       alert('Your facebook status updated'); 
      } 
      showLoader(false); 
      } 
     ); 
    } 

    function showLoader(status){ 
     if (status) 
      document.getElementById('loader').style.display = 'block'; 
     else 
      document.getElementById('loader').style.display = 'none'; 
    } 

</script> 

回答

0

他們是在FB對象使用這種破壞FB會話定義

$facebook->destroySession(); 

或者

功能,

使用(通過PHP)

FB API提供了一個logoutURL,用於將用戶從當前Facebook帳戶中註銷。

,你可以使用它像這樣,

$facebook = new Facebook($config); 
$params = array('next' => 'www.yousite.com/test.php'); 
$logoutURL = $facebook->getLogoutUrl($params); 

***注意 建議添加以下代碼也(沒有的情況下,如果你不希望你的用戶登錄你的網站)

//remove PHPSESSID from browser 
if (isset($_COOKIE[session_name()])) 
    setcookie(session_name(), '', time()-7000000, '/'); 
//clear session from globals 
    $_SESSION = array(); 

隨着JS使用定製事件 REF:(FB.logout() called without an access token. javascript sdk

function fbLogoutUser() { 
    FB.getLoginStatus(function(response) { 
     if (response && response.status === 'connected') { 
      FB.logout(function(response) { 
       document.location.reload(); 
      }); 
     } 
    }); 
} 
+0

感謝您回答我的問題 – DKBHOI

+0

現在爲您工作? –

+0

我使用fbLogoutUser()函數,這次它也註銷我的Facebook帳戶。任何更多的建議plz .. – DKBHOI

相關問題