サイトに接続ボタンを設定しようとしています。ユーザーがFacebookのログインボタンをクリックすると、ポップアップがユーザーに認証の詳細を入力するように求め、親ウィンドウがページをリダイレクトまたは更新し、ログインボタンがログアウトボタンになります。
私の問題は、ユーザーがポップアップから接続ボタンをクリックすると、ポップアップページがポップアップを閉じるのではなく、私のキャンバスページにリダイレクトされることです。
多くの人がこの問題を投稿しています。他のすべてを正しく行った場合、これは xd_receiver ファイルが fb によって読み取られなかったことが原因です。
fb接続ボタンがどこにあるかを確認する必要があります。そのページの下部にある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>
これは Facebook の接続、ログイン、ログアウトのサンプルです。非常にうまく機能します。また、アプリの設定 -> Web サイト -> サイト URL の下にサイトの URL を追加してください:
<!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>