【问题标题】:FaceBook FB.ui logout dont fireFaceBook FB.ui 注销不触发
【发布时间】:2011-12-08 02:36:58
【问题描述】:
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),但不确定我是否理解代码足以知道它按我的要求做!

【问题讨论】:

  • 如果您不使用注销按钮,那么您需要将应用程序访问令牌附加到注销 url “php-sdk” 我认为它不适用于 javascript,除非您构建注销 url自己。
  • 有趣的答案,但对我来说看起来像mumbojumbo...请给我一个例子,请提供一些代码!...我没那么聪明!

标签: facebook logout fb.ui


【解决方案1】:
  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权限。

我使用 cmets 框编写了一个示例来触发自动注销 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>

【讨论】:

  • 所有代码都不需要,你可以修改你看到的修复,只是想在我发布的例子中展示它是如何完成的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-02
  • 1970-01-01
  • 2012-05-04
  • 1970-01-01
  • 2021-02-27
相关资源
最近更新 更多