Facebook FB.ui 注销不会触发

发布于 2024-12-10 03:57:07 字数 1001 浏览 0 评论 0原文

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('postpublish') 后没有执行任何操作!

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

我发现:使用“服务器端工作流程”(OAuth 2.0)登录后会引发 FB auth.logout,但不确定我是否足够理解代码以知道它执行我要求的操作!

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.');
         }
       });
}

That code WORK fine, now i like after :

alert('Post was published.');

to be logged out from facebook, silently
HOW ?

Adding that code After the alert('post publish') did not do anything !!

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

i have found : FB auth.logout is being raised after being logged in using the "server-side-workflow" (OAuth 2.0) but not sure i understand the code enough to know it do what i ask !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2024-12-17 03:57:07
  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>
  1. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

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

Best Practices

FB.logout will log the user out of both your site and Facebook. You
will need to have a valid access token for the user in order to call
the function.

Calling FB.logout will also invalidate the access token that you have
for the user, unless you have the offline_access permission.

I wrote a sample using the comments box to fire the auto logout
http://shawnsspace.com/fb.logout.test.php

THE CODE:


    <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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文