Javascript Facebook“喜欢”按钮回调

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2798622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:57:44  来源:igfitidea点击:

Facebook "Like" button callback

javascriptfacebookbuttoncallbackfacebook-like

提问by Matt

I am interested in implementing the facebook "Like" button, but I would like to know what user is clicking on this button so I can get some useful information from this. From what I have read, facebook is leaving us in the dark on who is clicking on what. ANyone have an idea on how I could track which user clicked on a like button for a particular product?

我对实现 facebook 的“赞”按钮很感兴趣,但我想知道什么用户点击了这个按钮,这样我就可以从中获得一些有用的信息。从我读到的内容来看,Facebook 让我们对谁在点击什么一无所知。任何人都知道我如何跟踪哪个用户点击了特定产品的喜欢按钮?

UPDATE: The like button is rendered by facebook either through an iFrame, or through xFBML. This is why it is difficult to track who clicks on what, or embed an onclick event, etc..

更新:点赞按钮由 ​​facebook 通过 iFrame 或 xFBML 呈现。这就是为什么很难跟踪谁点击了什么,或者嵌入一个 onclick 事件等等。

回答by TLK

<script>
  FB.Event.subscribe('edge.create', function(href, widget) {
    alert('You just liked the page!');
  });
</script>

回答by James

so I simply rendered a unique like button for each logged in user with a URL of www.somewebsite.com/thisIsThePageIlike/facebookUID.

所以我简单地为每个登录用户渲染了一个独特的喜欢按钮,网址为 www.somewebsite.com/thisIsThePageIlike/facebookUID。

won't this defeat the purpose of having a like button and mess up your facebook search ranking? Every user will be liking a different url and so facebook will think you have a ton of pages each with a single like count.

这不会破坏拥有喜欢按钮的目的并弄乱您的 Facebook 搜索排名吗?每个用户都会喜欢不同的网址,因此 facebook 会认为您有大量页面,每个页面都有一个喜欢计数。

I am also having an issue with XFBML like buttons where the edge.create event isn't firing

我也有 XFBML 的问题,比如 edge.create 事件没有触发的按钮

回答by Matt

OK, so I can let you know how I implemented it. What I wanted to get was the UID of the facebook user clicking on the "Like" button inside my facebook connect app. I noticed when a user clicks on the "like" button, facebook fetches the URL passed to it from the button, so I simply rendered a unique like button for each logged in user with a URL of www.somewebsite.com/thisIsThePageIlike/facebookUID. When a request come to the web server with this url, it works like a callback and I process and record the UID if its the first time a user has clicked "like" (ie.. a record of this 'like' does not exist in the db). works for me.

好的,我可以让你知道我是如何实现它的。我想得到的是 Facebook 用户点击我的 facebook 连接应用程序内的“喜欢”按钮的 UID。我注意到当用户点击“喜欢”按钮时,facebook 会从按钮中获取传递给它的 URL,所以我只是为每个登录用户呈现一个唯一的喜欢按钮,URL 为 www.somewebsite.com/thisIsThePageIlike/facebookUID . 当请求使用此 url 到达 Web 服务器时,它的工作方式类似于回调,如果用户第一次单击“喜欢”,我会处理并记录 UID(即……此“喜欢”的记录不存在)在数据库中)。为我工作。

回答by Kamal Kumar

window.fbAsyncInit = function () {

    FB.Event.subscribe('edge.create', function (response) {
        alert('Liked');
        });
    }
    );
    FB.Event.subscribe('edge.remove', function (response) {
        alert('DisLiked')
    });
};

(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id))
        return;
    js = d.createElement(s);
    js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

HTML:-

HTML:-

<div id="fb-root"></div><div class="fb-like" data-href="https://www.facebook.com/testpage" data-layout="standard" data-action="like" data-size="small" data-show-faces="true"></div>

回答by Simon

It would be something like the one I have for my client's site such as

这将类似于我为我客户的网站所拥有的,例如

<iframe src="http://www.facebook.com/plugins/like.php?href=www.jesterkaraoke.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>