我正在尝试在我的网站上设置一个连接按钮。一旦用户点击了facebook登录按钮,弹出窗口将要求用户输入身份验证详细信息,父窗口将重定向或刷新页面,登录按钮成为注销按钮。
我的问题是当用户从弹出窗口中单击连接按钮时,弹出页面将重定向到我的画布页面而不是关闭弹出窗口。
答案 0 :(得分:2)
很多人都发布了这个问题,如果你做了其他正确的事情,原因是fb没有读取xd_receiver文件。
您需要确保fb connect按钮的位置,您在该页面底部的某处指定了xd_receiver.html文件的正确路径。如下所示:
<script type="text/javascript">
FB.init("your api key here", "xd_receiver.htm");
</script>
将xd_receiver文件放在站点的根文件夹上并使用完整的域URL指定它是更好更容易的,如下所示:
<script type="text/javascript">
FB.init("your api key here", "http://www.yoursite.com/xd_receiver.htm");
</script>
答案 1 :(得分:0)
以下是facebook连接,登录和注销的示例,效果很好, 另外,请确保在您的应用设置下添加您的网站网址 - &gt;网站 - &gt;网站网址:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Facebook Connect Sample</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
// do something on login
login();
});
FB.Event.subscribe('auth.logout', function(response) {
// do something on logout
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
login();
}
});
};
/* Loading the JS SDK Asynchronously - Refer: https://developers.facebook.com/docs/reference/javascript/ */
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login(){
window.location = "http://google.com"; // Redirect to Another Page.
/* Show User's Name
FB.api('/me', function(response) {
document.getElementById('login').style.display = "block";
document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
});
*/
}
function logout(){
document.getElementById('login').style.display = "none";
}
</script>
<p><fb:login-button autologoutlink="true"></fb:login-button></p>
<div id="login" style ="display:none"></div>
</body>
</html>