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

查看:37
本文介绍了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>

用于显示 Like & 的代码分享按钮:-

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

推荐答案

您无法使用此类似按钮获取共享回调.您可以改为创建您的共享按钮,并在点击时调用 Feed 对话框->

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天全站免登陆