对于你所说的你想要使用的饲料对话框。它非常灵活,您只需设置链接并传递一些变量即可。我没有看到您提到的Feed对话框正在被逐渐淘汰,它们的用途各不相同。我认为他们推动了这种方式,因为它更容易使用,并且不太可能被滥用。
您需要注册一个应用程序,并确保在调用下面的函数之前初始化Facebook JavaScript SDK。如果您的弹出窗口有问题,可能是由于您的FB init进程存在问题。我已经添加了第二个用于初始化Facebook的函数。这两个函数都使用jQuery,所以如果你不使用它,你可能需要修改。
您可以创建这样一个非常通用的功能:
$.shareMe = function(myName, myLink, myPicture, myCaption) {
FB.ui(
{
method: 'feed',
name: myName,
link: myLink,
picture: myPicture,
caption: myCaption
},
function(response) {
if (response && response.post_id) {
alert('Thanks for Sharing.');
} else {
alert('Post was not published.');
}
}
);
}
和Facebook的初始化:
$.initFacebook = function(options){
$('#fb-root').remove();
$('body').append('<div id="fb-root"></div>');
var settings = {
'appId' : null,
'callback' : null,
'channelUrl' : null,
'status' : true,
'cookie' : true,
'xfbml' : true
};
if (options) {
$.extend(settings, options);
}
if(typeof(xc_app_id) == 'undefined') { window.xc_app_id = settings.appId; }
window.fbAsyncInit = function() {
if(settings.channelUrl==null) {
FB.init({appId: settings.appId, status: settings.status, cookie: settings.cookie, xfbml: settings.xfbml, oauth: true, authResponse: true });
} else {
settings.channelUrl=location.protocol+'//'+settings.channelUrl;
FB.init({appId: settings.appId, status: settings.status, cookie: settings.cookie, xfbml: settings.xfbml, oauth: true, authResponse: true, channelUrl: settings.channelUrl });
}
if(typeof settings.callback == 'function'){ settings.callback.call(this); }
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
}
,并调用它,你只需要使用$ .initFacebook({APPID, 'yourAppId' });如果需要,还可以在文档中查找其他选项。
干杯的人。张贴后,我走了很长一段路,想了解我读过的内容。我决定,提要是用户可能拥有的不同活动的最佳方式,并且可以将其主页发布到墙上。为了将我的网站发布到他们的墙上,我会和Like一起去。我会看看这一切如何解决。感谢代码。最有用的。是的,我已经有一个ID,我使用JQuery。 – ants
该Feed非常灵活,并且有一些代码可以使用它。祝你的节目顺利。 –