通过 Facebook 分享对话框分享图片
Sharing image via Facebook Share Dialog
我为此共享对话框制作了一个 Facebook 应用程序来共享来自我的 Web 应用程序的图像,但每当我加载页面时,我都会收到此错误消息:
Uncaught: h message: "invalid version specified"
我试图通过阅读此处的一些旧帖子来解决此问题,但没有任何效果(尝试在 js.src
中提供参数,使用 all.js
而不是 sdk.js
)。这是正文标签之后的代码:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '224188011327825',
xfbml : true,
version : '2.8'
});
FB.AppEvents.logPageView();
};
(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'));
</script>
以及外部文件中的代码(Rails' application.js):
function shareFBImage() {
var imageUrl = document.getElementById("post-image").src;
FB.init({ appId: '224188011327825', status: true, cookie: true });
FB.ui(
{
method: 'share',
name: 'Facebook Dialogs',
href: $(location).attr('href'),
link: 'https://developers.facebook.com/docs/',
picture: imageUrl,
caption: '',
description: ''
},
function (response) {
if (response && response.post_id) {
alert('success');
} else {
alert('error');
}
}
);
}
问题已解决;我在这里初始化了 FB.init
第二次:
FB.init({ appId: '224188011327825', status: true, cookie: true });
我为此共享对话框制作了一个 Facebook 应用程序来共享来自我的 Web 应用程序的图像,但每当我加载页面时,我都会收到此错误消息:
Uncaught: h message: "invalid version specified"
我试图通过阅读此处的一些旧帖子来解决此问题,但没有任何效果(尝试在 js.src
中提供参数,使用 all.js
而不是 sdk.js
)。这是正文标签之后的代码:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '224188011327825',
xfbml : true,
version : '2.8'
});
FB.AppEvents.logPageView();
};
(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'));
</script>
以及外部文件中的代码(Rails' application.js):
function shareFBImage() {
var imageUrl = document.getElementById("post-image").src;
FB.init({ appId: '224188011327825', status: true, cookie: true });
FB.ui(
{
method: 'share',
name: 'Facebook Dialogs',
href: $(location).attr('href'),
link: 'https://developers.facebook.com/docs/',
picture: imageUrl,
caption: '',
description: ''
},
function (response) {
if (response && response.post_id) {
alert('success');
} else {
alert('error');
}
}
);
}
问题已解决;我在这里初始化了 FB.init
第二次:
FB.init({ appId: '224188011327825', status: true, cookie: true });