在有人在自己的网站上提交之前,先检查是否有人喜欢该页面 [英] Check if someone likes page before submit on own website

查看:33
本文介绍了在有人在自己的网站上提交之前,先检查是否有人喜欢该页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上有一个自己的页面,人们可以在其中下载自己的曲目.

我的想法是在该页面上放置一个喜欢按钮到我的Facebook页面.人们必须先按赞"按钮,然后才能下载曲目.可能必须使用带有必须单击的名称,电子邮件和类似按钮的表单来解决此问题!提交后,必须有一些东西可以检查用户是否真的点击了赞"按钮,然后才获得具有特殊内容的页面(下载链接)

因此,我们的想法是,在提交并获得下载按钮之前,是否有可能先检查该页面是否被喜欢!

有人可以告诉我这是否可行,有人可以帮助我提供代码吗? 我没有其他Facebook社交插件!我只想使用一个赞按钮!

解决方案

您可以检查是否有人使用Javascript SDK单击了点赞按钮

您可以使用社交插件或XFBML按钮, 实施XFBML按钮和Javascript SDK,您可以在这里找到: https://developers.facebook.com/docs/reference/javascript/

然后,您可以创建一个事件侦听器,该事件侦听器在用户单击赞"按钮时进行侦听:

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
    } 
);

https://developers.facebook.com/docs/reference /javascript/FB.Event.subscribe/

使用它可以存储是否有人单击了喜欢"按钮,然后将其保存到您的数据库或会话中,并让用户下载其曲目.

您的代码将是这样

<div id="fb-root"></div>
<div class="fb-like" data-href="http://www.stackoverflow.com" data-send="false" data-width="450" data-show-faces="true"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'YOUR_APP_ID', // App ID
            channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
        });

        FB.Event.subscribe('edge.create',
            function(response) {
                alert('You liked the URL: ' + response);
            } 
        );
    };

// Load the SDK Asynchronously
(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));

I have a own page on my server where people can download a track of my own.

My idea is to put a like button on that page to my Facebook page. People must first hit the like button, and after that they can download the track. Probably this must fix with a form with name, e-mail and the like button that they have to click! After submit, there must be something that will check if the user realy hit the like button before they get the page with the special content (download link)

So the idea is if it is possible that there's a check that the page is liked before they can submit and get the download button!

Can someone tell me if this is possible and can someone help me with the code? I have no other Facebook social plugins! I only want to use a like button!

解决方案

You can check if someone clicks the like button using the Javascript SDK

You can either use the social plugin or the XFBML button, Implementing the XFBML button and the Javascript SDK you can find here: https://developers.facebook.com/docs/reference/javascript/

Then you can create an event listener that listens if an user clicks the like button:

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
    } 
);

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

Using this you can store if someone clicked the like button then save that to either your database or in a session and let the user download their track.

Your code would be something like this

<div id="fb-root"></div>
<div class="fb-like" data-href="http://www.stackoverflow.com" data-send="false" data-width="450" data-show-faces="true"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'YOUR_APP_ID', // App ID
            channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
        });

        FB.Event.subscribe('edge.create',
            function(response) {
                alert('You liked the URL: ' + response);
            } 
        );
    };

// Load the SDK Asynchronously
(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));

这篇关于在有人在自己的网站上提交之前,先检查是否有人喜欢该页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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