Check if someone likes page before submit on own website

半世苍凉 提交于 2019-12-01 14:50:27

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));

Jarede

It is possible to do what you're asking. You may find this SO question and answer useful:

How to check if a user likes my Facebook Page or URL using Facebook's API

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!