这是我的代码,从开始的正文标签下方开始:
<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>
登录功能工作正常,但之后无法调用此脚本标签中的功能。不仅如此,奇怪<script>
的是,在 Facebook 脚本代码之后,它们中的 javascript 完全不工作。没有调用任何调试警报()函数,也没有调用(我可以告诉 Facebook)。
我考虑过一些可能的问题,但不确定:
- 我使用 php 调用页眉和页脚,这段代码在页眉中,不太确定这是否会影响任何加载方式
- 我通过它访问的域是受密码保护的,也就是说,当我导航到这个 url 时会弹出一个窗口,我需要登录才能看到该页面,不太确定这是否与 Facebook 的 SDK/服务器混淆
- 也许有一个我没有看到的相当明显的解决方案
任何帮助将不胜感激,因为我目前正疯狂地试图解决这个问题,谢谢!