我在以下代码中收到 javascript 错误。我得到的错误是“Uncaught ReferenceError: FB is not defined. postToFeed (anonymous function)”。有人可以帮我弄这个吗?提前致谢。
window.fbAsyncInit = function() {
FB.init({
appId : '<?= APP_ID ?>', // App ID
channelUrl : '.....', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// 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 postToFeed() {
var obj = {
method: 'feed',
link: '<?= REDIRECT_URL ?>',
picture: '<?= SHARE_IMAGE ?>',
name: unescape('<?= SHARE_TITLE ?>'),
caption: unescape('<?= SHARE_CAPTION ?>'),
description: unescape('<?= SHARE_DESCRIPTION ?>')
};
function callback(response) {
console.log(response);
//alert("Message posted to your wall, thanks!");
if (response && response.post_id) {
alert('Success');
window.location="page.php";
} else {
alert('Fail.');
}
}
FB.ui(obj, callback);
}
function sendToFriend() {
var obj = {
method: 'send',
link: '<?= REDIRECT_URL ?>',
picture: '<?= SHARE_IMAGE ?>',
name: unescape('<?= SHARE_TITLE ?>'),
caption: unescape('<?= SHARE_CAPTION ?>'),
description: unescape('<?= SHARE_DESCRIPTION ?>')
};
function callback(response) {
console.log(response);
//alert("Message sent to your friend(s), thanks!");
if (response && response.post_id) {
alert("Success!");
window.location="page.php";
} else {
alert('Fail.');
}
}
FB.ui(obj, callback);
}