考虑网页上的网址列表(例如example.com
),该网址定位到另一个网域(例如domain.com
)。
是否可以为每个URL创建Facebook Like按钮,这些按钮会将消息添加到用户时间线中的Like帖子,例如"Found on example.com"
,同时仍然链接到domain.com
上的原始网址?
答案 0 :(得分:3)
正如@ miken32所说。直接的方法是不可能的。为了达到这个目的,你可以做到这一点......
我们使用FB.Event.subscribe在有人通过您网页上的嵌入式按钮喜欢某些内容时收到回电。语法如下:
// callback that logs arguments
var page_like_callback = function(url, html_element) {
console.log("page_like_callback");
console.log(url);
console.log(html_element);
}
// In your onload handler add this call
FB.Event.subscribe('edge.create', page_like_callback);
FB.Event.subscribe('edge.remove', page_unlike_callback);
在CallBack功能中,使用此代码使用feed
发布您想要的网址FB.ui({
method: 'feed',
link: 'link to domain.com',
caption: 'Found on example.com',
}, function(response){});
OR
<强>更新强>:
将出现使用FB.ui对话框以供用户确认操作。如果不希望使用FB.api。这需要您指定'publish_stream'权限
var params = {};
params['message'] = 'Found on example.com';
params['name'] = 'Heading';
params['description'] = 'Description, if needed';
params['link'] = 'domain.com';
params['picture'] = 'Images if needed';
params['caption'] = 'Found on example.com';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Published to stream - you might want to delete it now!');
}
});
FB.login(function(response) {
// handle the response
}, {scope: 'publish_stream'});
最后它会是这样的
// callback that logs arguments
var page_like_callback = function(url, html_element) {
FB.ui({
method: 'feed',
link: 'link to domain.com',
caption: 'Found on example.com',
}, function(response){});
}
或更好一个
var page_like_callback = function(url, html_element) {
var params = {};
params['message'] = 'Found on example.com';
params['name'] = 'Heading';
params['description'] = 'Description, if needed';
params['link'] = 'domain.com';
params['picture'] = 'Images if needed';
params['caption'] = 'Found on example.com';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Published to stream - you might want to delete it now!');
}
});
}
此外,
// In your onload handler add this call
FB.Event.subscribe('edge.create', page_like_callback);
FB.Event.subscribe('edge.remove', page_unlike_callback);
FB.login(function(response) {
// handle the response
}, {scope: 'publish_stream'});