这是我的代码,从开始正文标记的正下方开始:
<div id="fb-root"></div>
<script>
alert("made it into the script");
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '360348567392858', // App ID from the App Dashboard
channelUrl : 'http://chrisvanhorne.com/users/erosas/final/channel.html', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// User logged into FB and authorized
testAPI();
document.getElementById('fb-logout').style.display = 'block';
} else if (response.status === 'not_authorized') {
// User logged into FB but not authorized
login();
} else {
// User not logged into FB
login();
document.getElementById('fb-logout').style.display = 'block';
}
});
};
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
alert("made it to login");
testAPI();
} else {
// cancelled
}
});
}
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
}
// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might
// contain some type checks that are overly strict.
// Please report such bugs using the bugs tool.
(function(d, debug){
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" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>
登录功能正常,但之后不能对此脚本标记内的函数进行调用。不仅如此,奇怪的是,在Facebook脚本代码之后,其中没有<script>
的javascript工作。没有调用alert()函数被调用,也没有调用(我可以告诉Facebook)。
我考虑过的一些可能的问题,但我不确定:
任何帮助都会非常感激,因为我现在正疯狂地试图解决这个问题,谢谢!
答案 0 :(得分:0)
令人难以置信,部分原因是因为代码没有等待init函数完成,因为头部(未显示)中有“坏”的javascript标签结束为:而不是。轻松修复,下次将更难寻找答案