簡體   English   中英

Facebook JavaScript SDK登錄按鈕沒有彈出權限

[英]Facebook JavaScript SDK Login Button Doesn't Pop Up Permission

我為創建的許多Facebook應用程序使用了很長時間以下代碼,但是從幾個小時前開始,此代碼似乎不再起作用。 我不知道此代碼是否可以不再使用或暫時不可用。 是否有與以下代碼相似的替代代碼?

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>FB APP</title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<style>
body{
    background: #ffffff url('lp.jpg') top center no-repeat;
    margin-left: 160px;
}
@font-face {
    font-family:fabada;
    src: url('fabada.ttf');
}
#likegate{
    text-align: center;
    margin-top: 400px;
    margin-left: 350px;
    padding-bottom: 100px;
}
</style>
</head>
<body>
<!-- DEFINITING FACEBOOK APP ID -->
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
    FB.init({
        appId   : '448829841800709',
        status  : true, // check login status
        cookie  : true, // enable cookies to allow the server to access the session
        xfbml   : true  // parse XFBML
    });
    FB.UIServer.setActiveNode = function(a,b){FB.UIServer._active[a.id]=b;}
    // Scroll Bar Fixed
    window.setTimeout(function() {
        FB.Canvas.setAutoResize(90);
        FB.Canvas.setAutoResize();
        FB.Canvas.setSize({ width: 810, height: 555 });
    }, 250);
</script>
<script type="text/javascript">
function loging(getuid){
jQuery("#loginfb").hide();
jQuery("#fbload").show();
FB.api(
          {
            method: 'fql.query',
            query: 'SELECT name, uid FROM user WHERE uid=' + getuid 
          },
          function(response) {
            var user = response[0];
            jQuery.ajax({
            type: 'GET',
            url: 'login.php?uid=' + getuid,
            success: function(data) {
                jQuery('#jstarget').html(data);
                jQuery("#fbload").hide();
            }
            });
          }
        );        
}

window.fbAsyncInit = function () {
FB.init({
          appId   : '448829841800709',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth   : true
        });
}

jQuery(document).ready(function() {
    // fetch the status on load
    jQuery('#loginfb').bind('click', function() {
        FB.init({
              appId   : '448829841800709',
              status  : true, // check login status
              cookie  : true, // enable cookies to allow the server to access the session
              xfbml   : true, // parse XFBML
              oauth   : true
            });
        if (response.authResponse){
            FB.api('/me', function(response) {
            loging(response.id);
            }); 
        } 
        else{
            //user is not connected to your app or logged out
            FB.login(function(response) {
                if(response.authResponse) {
                    FB.api('/me', function(response) {
                    loging(response.id);
                    });
                } 
                else {
                    //user cancelled login or did not grant authorization
                }
            }, {scope:'publish_stream'});   
        }
    });
    // handle a session response from any of the auth related calls
});
</script>
<div id="jstarget"></div>

<div id="box">
    <!--MAIN CONTENT-->
    <div id="content">
        <div id="likegate">
            <img src="login.png" style="cursor: pointer; float: left;" id="loginfb" alt="Login">
            <img src="ajax-loader.gif" style="float: left; padding-left: 50px; display:none" id="fbload" alt="Loading">
        </div>
    </div>
</div>
</body>
</html>

更新

當我刪除這個

if (response.authResponse){
    FB.api('/me', function(response) {
    loging(response.id);
    }); 
}
else{
   // this code here not removed
}

它顯示彈出權限對話框,但是當我允許該應用程序時,我再次單擊登錄按鈕,為什么它又顯示彈出權限對話框?

您需要刪除所有多個FB.init,不要在jquery 1.7.1之后使用.bind(),它將被.on()貶值。

2)添加channel.html,它應該可以幫助您解決任何XD問題。 3)使用FB.getAuthResponse()獲得身份驗證響應

我做了快速清理,但從未測試! 而且看起來還有很多改進的空間:

<!-- DEFINITING FACEBOOK APP ID -->
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '448829841800709', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

     FB.UIServer.setActiveNode = function(a,b){FB.UIServer._active[a.id]=b;}
    // Scroll Bar Fixed
    window.setTimeout(function() {
        FB.Canvas.setAutoResize(90);
        FB.Canvas.setAutoResize();
        FB.Canvas.setSize({ width: 810, height: 555 });
    }, 250);

  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
<script type="text/javascript">
function loging(getuid){
    jQuery("#loginfb").hide();
    jQuery("#fbload").show();
    FB.api(
              {
                method: 'fql.query',
                query: 'SELECT name, uid FROM user WHERE uid=' + getuid 
              },
              function(response) {
                var user = response[0];
                jQuery.ajax({
                type: 'GET',
                url: 'login.php?uid=' + getuid,
                success: function(data) {
                    jQuery('#jstarget').html(data);
                    jQuery("#fbload").hide();
                }
                });
              }
            );        
}


jQuery(document).ready(function() {
    // fetch the status on load
    jQuery('#loginfb').on('click', function() {

        if (FB.getAuthResponse()){
            FB.api('/me', function(response) {
            loging(response.id);
            }); 
        } 
        else{
            //user is not connected to your app or logged out
            FB.login(function(response) {
                if(response.authResponse) {
                    FB.api('/me', function(response) {
                    loging(response.id);
                    });
                } 
                else {
                    //user cancelled login or did not grant authorization
                }
            }, {scope:'publish_stream'});   
        }
    });
    // handle a session response from any of the auth related calls
});
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM