2

Consider a list of URLs on a page (e.g. example.com), which target another domain (e.g. domain.com).

Is it possible to create Facebook Like buttons for each URL that would add a message to a Like post in the user's timeline, e.g. "Found on example.com", while still linking to the original URL on domain.com?

4

1 回答 1

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发布您想要的 URL

FB.ui({
  method: 'feed',
  link: 'link to domain.com',
  caption: 'Found on example.com',
}, function(response){});

或者

更新

将出现使用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'});
于 2014-02-19T07:55:54.663 回答