我尝试将fb登录集成到我的网站上,无法让它工作。我提到了其他帖子和教程,但我仍然无法让它发挥作用。
<html>
<head>
<title>My Facebook Login Page2</title>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '317329008329948', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
login();
});m
FB.Event.subscribe('auth.logout', function(response) {
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
greet();
}
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login(){
FB.api('/me', function(response) {
alert('You have successfully logged in, '+response.name+"!");
});
}
function logout(){
alert('You have successfully logged out!');
}
function greet(){
FB.api('/me', function(response) {
alert('Welcome, '+response.name+"!");
});
}
</script>
<fb:login-button autologoutlink='true' perms='email,user_birthday,status_update,publish_stream'></fb:login-button>
</body>
</html>
我一直收到此错误:“发生了错误,请稍后再试”
答案 0 :(得分:3)
请不要盲目使用Facebook在其示例中显示的回调,并忽略响应值。即使该动作确实没有执行,Facebook也会调用这些事件。这就是为什么他们给你“响应”变量。
在决定要做什么之前,您应该查看响应变量属性的值。
我向markzzz提出了同样的建议,并为他工作
答案 1 :(得分:1)
根据我的经验, 当我将我的fb代码放在应用程序设置中指定的网站之外时,我收到此错误。
因此,我建议您在应用设置中Site URL
中指定的同一网址上运行代码。