ユーザーが私のindex.htmlページのリンクをクリックした後、facebook javascript sdkを初期化し、ログインステータスを確認したいと考えています。何らかの理由で、これは機能しません。jQueryは機能しており、initコードを個別にテストすると機能しますが、まとめると機能しなくなります。理由はありますか?
これは私の index.html ページです:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>
// この jquery は init プロセスをトリガーするはずです
$('document').ready(function(){
$('a').click(function(){
alert("this works");
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : '39672*******', // App ID
channelUrl : '//http://spilot.koding.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
});
// get login status
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// connected: redirect to start scene page
alert("testing");
} else if (response.status === 'not_authorized') {
// not_authorized
login();
} else {
// not_logged_in
login();
}
});
};
// 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) {
// connected
alert("connected");
} else {
// cancelled
}
});
}
});
});
</script>
<div id="findScene"><a href=""><h1>Find</h1></a></div>
<div id="startScene"><a href=""><h1>Host</h1></a></div>
</body>
</html>