2017-05-03 133 views
1

我坚持登录到我的网站使用Facebook,但我一直得到这个问题,当我点击Facebook登录按钮弹出显示并立即隐藏我如何登录到我的网站使用Facebook社会登录

我已经在使用Facebook的文档代码Web登录尝试

<!DOCTYPE html> 
<html> 
<head> 
<title>Facebook Login JavaScript Example</title> 
<meta charset="UTF-8"> 
</head> 
<body> 
<script> 
    // This is called with the results from from FB.getLoginStatus(). 
    function statusChangeCallback(response) { 
    console.log('statusChangeCallback'); 
    console.log(response); 
    // The response object is returned with a status field that lets the 
    // app know the current login status of the person. 
    // Full docs on the response object can be found in the documentation 
    // for FB.getLoginStatus(). 
    if (response.status === 'connected') { 
     // Logged into your app and Facebook. 
     testAPI(); 
    } else { 
     // The person is not logged into your app or we are unable to tell. 
     document.getElementById('status').innerHTML = 'Please log ' + 
     'into this app.'; 
    } 
    } 

    // This function is called when someone finishes with the Login 
    // Button. See the onlogin handler attached to it in the sample 
    // code below. 
    function checkLoginState() { 
    FB.getLoginStatus(function(response) { 
     statusChangeCallback(response); 
    }); 
    } 

    window.fbAsyncInit = function() { 
    FB.init({ 
    appId  : '{your-app-id}', 
    cookie  : true, // enable cookies to allow the server to access 
         // the session 
    xfbml  : true, // parse social plugins on this page 
    version : 'v2.8' // use graph api version 2.8 
    }); 

    // Now that we've initialized the JavaScript SDK, we call 
    // FB.getLoginStatus(). This function gets the state of the 
    // person visiting this page and can return one of three states to 
    // the callback you provide. They can be: 
    // 
    // 1. Logged into your app ('connected') 
    // 2. Logged into Facebook, but not your app ('not_authorized') 
    // 3. Not logged into Facebook and can't tell if they are logged into 
    // your app or not. 
    // 
    // These three cases are handled in the callback function. 

    FB.getLoginStatus(function(response) { 
    statusChangeCallback(response); 
    }); 

    }; 

    // Load the SDK asynchronously 
    (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')); 

    // Here we run a very simple test of the Graph API after login is 
    // successful. See statusChangeCallback() for when this call is made. 
    function testAPI() { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Successful login for: ' + response.name); 
     document.getElementById('status').innerHTML = 
     'Thanks for logging in, ' + response.name + '!'; 
    }); 
    } 
</script> 

<!-- 
    Below we include the Login Button social plugin. This button uses 
    the JavaScript SDK to present a graphical Login button that triggers 
    the FB.login() function when clicked. 
--> 

<fb:login-button scope="public_profile,email" onlogin="checkLoginState();"> 
</fb:login-button> 

<div id="status"> 
</div> 

</body> 
</html> 

我用下面

此链接

感谢您的帮助

+0

您好,欢迎StackOverflow上。请花一些时间阅读帮助页面,特别是关于[最小,完整和可验证示例]一节(http://stackoverflow.com/help/mcve) –

回答

0

Facebook社交插件:登录按钮的Facebook提供了他们所谓的社交插件的主机。我们感兴趣的是登录按钮。以下是将按钮放到网页上的基本步骤:

您需要为您的网站安装Facebook应用程序。转到https://developers.facebook.com/apps/并点击“新应用”按钮。

你的“应用显示名称”可以是有意义的。我通常会使用该网站的域名。您也可以在未来将其用于其他目的。 “应用程序名称空间”需要是不包含任何特殊字符的内容。我通常使用我的应用程序显示名称,不含空格,句点等。现在您需要输入您的“应用程序域”和网站“网站URL”。为应用程序域输入您的网站托管的域名。对于网站网址,请输入您网站的完整网址。例如,如果您的域名是name.com,那么您的网站网址应该是http://www.your_domain.com。一旦你输入了正确的信息,保存你的修改。现在您将有一个页面显示您的“应用程序ID”和“应用程序秘密”。只需将该页面保持打开状态,因为在将登录按钮代码添加到页面时,您将需要您的应用程序ID。现在我们需要从Facebook获取登录按钮代码。转到http://developers.facebook.com/docs/reference/plugins/login/并单击“获取代码”按钮。从第一个框中复制HTML5代码,现在将它放在网页正文标签下方。代码应该是这个样子:

<div id="fb-root"></div> 
<script> 
    (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/all.js#xfbml=1&appId=APP_ID"; 
    fjs.parentNode.insertBefore(js, fjs); 
    } (document, 'script', 'facebook-jssdk')); 
</script> 

在代码中一定要与你的Facebook应用程序创建的应用程序ID替换APP_ID。现在将第二个框中的代码粘贴到任何您想要登录按钮的地方。该代码应该是这个样子:

<div class="fb-login-button" data-show-faces="false" data-width="200" data-max-rows="1"></div> 

数据显示,面孔等于假的,因为它设置为true,当用户登录注销按钮会显示

相关问题