0

无需单击登录按钮即可出现登录对话框。

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

检查我的网站http://wwwtechnologies.com/ 我在 fb 应用程序中给出了这个设置 应用程序域: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 -->
4

1 回答 1

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>
于 2012-12-19T11:16:13.577 回答