FaceBook FB.ui注销不要开火

时间:2011-10-14 21:57:31

标签: facebook logout fb.ui

FB.ui(
       {
         method: 'feed',
         name: 'some text',
         link: 'some text',
         picture: 'aa.jpg',
         caption: 'some text',
         description: 'some text',
         message: 'some text'
       },
       function(response) {
         if (response && response.post_id) {
            alert('Post was published.');               
        } else {
            alert('Post was not published.');
         }
       });
}

该代码工作正常,现在我喜欢之后:

alert('Post was published.');

从facebook登出,默默地 怎么样?

添加该代码alert('post publish')没有做任何事情!!

FB.ui(
 { method:'auth.logout',  display:'hidden' },
 function() { alert("you're logged out!"); }
);

我找到了:FB auth.logout is being raised after being logged in using the "server-side-workflow" (OAuth 2.0)但不确定我是否完全了解代码,知道它按照我的要求行事!

1 个答案:

答案 0 :(得分:2)

  1. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

  2. https://developers.facebook.com/docs/reference/javascript/FB.logout/

  3.   

    最佳做法

         

    FB.logout会将用户从您的网站和Facebook中注销。您   将需要为用户提供有效的访问令牌才能进行调用   功能。

         

    调用FB.logout也会使您拥有的访问令牌无效   对于用户,除非您具有offline_access权限。

    我使用评论框编写了一个示例来触发自动注销 http://shawnsspace.com/fb.logout.test.php

    代码:


        <div id="fb-root"></div>    
        <script>
          window.fbAsyncInit = function() {
            FB.init({
        appId  : '112104298812138',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true, // parse XFBML
        //channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
        oauth  : true // enable OAuth 2.0
            });
    FB.Canvas.EarlyFlush.addResource("http://shawnsspace.com/index.php");
    FB.Canvas.setAutoResize();
                FB.getLoginStatus(function(response) {
                  if (response.authResponse) {
    
                    var accessToken = response.authResponse.accessToken;
                  } else {
                  }
                }); 
        FB.Event.subscribe('comment.create', function(response) {
         //alert(JSON.stringify(response));
            FB.logout(function(response) {
            window.location.reload();
            });
        });
            FB.Event.subscribe('auth.login', function(response) {
            //top.location.href = 'http://apps.facebook.com/shawnsspace/fbcomments.php?ref=loggedin';
            window.location.reload();
            });
            FB.Event.subscribe('auth.logout', function(response) {
            //top.location.href = "http://apps.facebook.com/shawnsspace/fbcomments.php?ref=loggedout";
            alert('logged out');
            });
          };
          (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>