获取FB未定义错误

时间:2016-03-11 11:14:27

标签: javascript facebook

我尝试了很多解决方案,但仍然没有定义FB错误。基本的想法是点击Facebook图标在我的Facebook墙上分享图像。下面是我的代码,它位于.js文件中。

window.fbAsyncInit = function() {
    FB.init({
appId      : '7895784589567515249',
xfbml      : true,
version    : 'v2.3',
status     : true
});
};

(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function shareOnFb(id,route,imageUrl,description,title,type) {
var caption;
var protocol = window.location.protocol;
var hostname = window.location.host;
var share_url = protocol+"//"+hostname+"/"+route;
var share_image = imageUrl;
if(type == "news") {
    caption="News @ testExample";
    share_image = imageUrl;
} else if(type == "story") {
    caption="Read this book";
}else {
    caption= "View this Charac";
}
FB.ui({
method: 'feed',
link: share_url,
caption: caption,
description:description,
picture:share_image,
name:title
}, function(response){
if(response) {
if(response.post_id) {
callfunction(id,type,"facebook");   
}
else {
$('.errorMessage').html("Could Not share on facebook");
$("#errorMsg_popup").modal();
}
}
else {
$('.errorMessage').html("Could Not share on facebook");
$("#errorMsg_popup").modal();
}
});
}

下面是我点击facebook图标时调用上述功能的代码片段。

<img src="{{../cdn_url}}/images/FB_Icon.png" onclick="shareOnFb({{this._id}},'users/myCharacters/{{this._id}}/posterView','{{this.char_thumbnail_url}}','','{{this.fb_name}}','characters')">

0 个答案:

没有答案