Facebook喜欢和分享按钮与回调 [英] Facebook like and share button with callback

查看:1879
本文介绍了Facebook喜欢和分享按钮与回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我放置了一个Facebook喜欢&共享按钮和相应的javascript回调函数。

I have a webpage where I have placed a Facebook like & share button and corresponding javascript callback functions are also present.

现在的问题是,javascript回调仅在用户喜欢时才触发, 分享按钮被按下。

Now the problem is, the javascript callback fires only when the user 'likes' and doesn't seem to fire when the 'share' button is pressed.

它像我需要奖励用户每次他/她分享的链接。而喜欢,用户只能喜欢一个链接(不考虑不同/不喜欢)。

Its like I need to award the user everytime he/she shares the link. Whereas with 'like', a user can only like a link once (not considering unlike/re-like).

我知道共享按钮已被弃用。但Facebook现在提供了一个类似按钮的共享按钮。资料来源: https://developers.facebook.com/docs/plugins/like-button/

I know that the Share button is deprecated. But facebook now provides a share button with a like button. Source : https://developers.facebook.com/docs/plugins/like-button/

有没有办法从此共享按钮启动此回调方法?

Is there a way to fire this callback method from this share button?

这是我的代码:

在我的HTML的BODY标记开头的代码:

<div id="fb-root"></div>

<script>
    window.fbAsyncInit = function() {
    FB.init({
        appId: ' My App ID ',
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true
    });
    FB.Event.subscribe('edge.create', function(response) {
        alert('You liked the URL: ' + response);

      });
};
(function(d) {
    var js, id = 'facebook-jssdk';
    if (d.getElementById(id)) {
        return;
    }
    js = d.createElement('script');
    js.id = id;
    js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    d.getElementsByTagName('head')[0].appendChild(js);
}(document));

        </script>

分享按钮: -

<div class="fb-like" data-href=" My URL " data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>


推荐答案

您无法使用此按钮获取共享回调。您可以创建自己的共享按钮,并在其点击调用 Feed对话 - p>

You cannot get the share callback using this like button. You can instead create a share button of yours and invoke the Feed Dialog on its click-

FB.ui(
{
  method: 'feed',
  name: 'Facebook Dialogs',
  link: 'https://developers.facebook.com/docs/dialogs/',
  picture: 'http://fbrell.com/f8.jpg',
  caption: 'Reference Documentation',
  description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
  if (response && response.post_id) {
    alert('Post was published.');
  } else {
    alert('Post was not published.');
  }
}
);

这篇关于Facebook喜欢和分享按钮与回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆