3
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 在使用“服务器端工作流程”(OAuth 2.0)登录后被提出,但不确定我是否理解代码足以知道它按我的要求做!

4

1 回答 1

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

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

最佳实践

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>
于 2011-10-15T04:38:40.487 回答