Facebook SDK创建Facebook链接注销

时间:2014-07-18 00:17:52

标签: html facebook facebook-graph-api facebook-javascript-sdk logout

如何在我的网站上添加按钮以注销当前的facebook会话?我已经有一个访问令牌并确认用户已登录,如果他们到达此页面,那么他们应该可以注销facebook。

HTML:

<body>
  <button onclick="FB.logout();">Log out of Facebook</button>
  <div id="fb-root"></div>
</body>
<script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'APP-ID',
      status     : true,
      xfbml      : true,
      version    : 'v2.0'
    });

    FB.getLoginStatus(function(response) {
     if (response.status === 'connected') {
        console.log("connected");
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token 
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        console.log(uid);
        console.log(accessToken);
      } else if (response.status === 'not_authorized') {
        console.log("not authorized");
        // the user is logged in to Facebook, 
        // but has not authenticated your app
      } else {
        console.log("not logged in");
        // the user isn't logged in to Facebook.
      }
    });

    FB.logout(function(response) {
        //document.location.reload();
        console.log("user logged out");
    });

  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>

控制台:

"FB.logout() called without an access token." sdk.js:54
Use of getUserData() or setUserData() is deprecated.  Use WeakMap or element.dataset instead. requestNotifier.js:63
"connected" callback:106
"{UID}" callback:114
"{ACCESS-TOKEN}" callback:115
Use of getUserData() or setUserData() is deprecated.  Use WeakMap or element.dataset instead. requestNotifier.js:63
Load denied by X-Frame-Options: https://www.facebook.com/home.php does not permit framing

单击该按钮时,所有发生的事情都会打印到控制台:

Use of getUserData() or setUserData() is deprecated.  Use WeakMap or element.dataset instead. requestNotifier.js:63
Load denied by X-Frame-Options: https://www.facebook.com/home.php does not permit framing

任何帮助表示赞赏!谢谢

0 个答案:

没有答案