我的网站中的Facebook登录对话框

时间:2012-12-19 11:08:39

标签: javascript facebook login sdk

登录对话框不会点击登录按钮。

如何在不点击“登录”的情况下停止加载对话框

检查我的网站http://wwwtechnologies.com/ 我在fb应用程序中给出了这个设置 App Domain:wwwtechnologies.com 有Facebook登录的网站:http://wwwtechnologies.com/

另一个问题:

如何获取该人的Facebook名称

<!-- FB LOGIN -->

<div id="fb-root"></div>
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId      : 'xxxxxxxx', // App ID
//channelUrl : '//wwwtechnologies.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.getLoginStatus(function(response) {
if (response.status === 'connected') {
// connected
} else if (response.status === 'not_authorized') {
// not_authorized
login();
} else {
// not_logged_in
login();
}
});
// Additional init code here

};

// 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));

function login() {
FB.login(function(response) {
if (response.authResponse) {
testAPI();

window.location.href = "index.php";
// connected
} else {
// cancelled
}
});
}

function testAPI() {
console.log('Welcome!  Fetching your information.... ');
FB.api('/me', function(response) {
//var myname = '+response.name+';
//alert(myname);
console.log('Good to see you, ' + response.name + '.');
});
}
</script>

<!-- FB LOGIN -->

1 个答案:

答案 0 :(得分:0)

加载JavaScript SDK后立即调用window.fbAsyncInit函数。在该函数中,您已经放置了FB.getLoginStatus逻辑。您要做的是从FB.getLoginStatus中取出window.fbAsyncInit并在用户点击您的登录按钮时触发它。

function doLogin(){
  FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
      // connected
    } else if (response.status === 'not_authorized') {
      // not_authorized
      login();
    } else {
      // not_logged_in
      login();
    }
  });
}


<button onclick="doLogin();">Login</button>