Facebook Like To Download Using Facebook API jquery

Facebook like button in web pages will bring lots of traffic to our website.But to make it more viral you could always give freebies and make people to like your fan page.(ie) You give freebies only for the user’s who have liked your fanpage.There is a premium plugin for doing this in wordpress(LINK).This tutorial will tell you how to make this script for free using facebook api.It is very simple,just we need to check weather a user has liked our facebook page or not using facebook api.

 

Technologies Used

  • Facebook API
  • Jquery(Ajax call)
To get a clear idea of this check out the demo link.You will automatically get this script once you liked our fan page there.
demo
Step 1:
To detect weather a user has clicked like  edge.create is used
 

FB.Event.subscribe('edge.create',function(response) {

    download();
});
Step 2:
If suppose the user have already liked the page,following code is used to handle it.
FB.api("me/likes/270801249647033", function(response) {
			      if ( response.data.length == 1 ) { //there should only be a single value inside "data"

				  download();
	 } else {
		//do nothing
 }});
Step 3:
We need to hide the download url from the front end.Hence a ajax call is did to get the download link in the download function
$.post("download.php",{url:"http://www.facebook.com/pages/Webtutsinfo/270801249647033"}, function(data) {
		location.href=data;
		$("#like").fadeOut();
 });
There are some drawbacks in this, because the user may unlike again after he download the script.But a loyal user wont do it.But to prevent that we are removing the like button from the DOM after the user has liked the page.
Download this script from the demo link itself(Download automatically starts once u liked the page).Subscribe our blog for upcoming posts in facebook API’s
For any queries comment below.
0saves
If you like this post, contribute us by sharing this in your network

, ,

  • http://www.facebook.com/erwin.schro Erwin Ariza

    i don;t get any download link or file after like-ing it. Is this still works or? let us know then.

  • Anonymous

    Hi Erwin! 

      There was a problem in the download link.Now i changed the download link. It works PERFECT. Thanks for pointing it out.

  • http://www.cbil360.com/ Web Design Company

    Useful tutorial about facebook API jQuery to check a user has liked to your facebook page or not? Cool stuff to use it and be up-to-date with social media.

  • nino

    yes the like button will missing after user press like to download,
    but see the like button will appear again if the user reload the page? then of course they can unlike back

  • Anonymous

    Hey nino .Thanks for your comment.The script checks when the document is loaded whether the user is the fan of the page.If he is not a fan only then the button is displayed.Any ways during the processing time of facebook api the button will be shown.But as i said in my post a loyal user wont unlike unless he really hates that page :)

  • Sam Skirrow

    This is agreat script, thanks for posting. Is there any way to add a manual download link when a person is already a fan of the facebook page??

  • Anonymous

    Hey sam. A manual download link is possible. Just some modification in the same code what i used in the demo script will do it.

  • Sam Skirrow

    Thats great news, can you advise on what modifications I would need to implement??

  • Anonymous

    Hey sam it is possible. Just modify the codes what i used in the demo.

  • Anonymous

    Trigger the download() function when ever the manual button is clicked for downloading the files.

  • Anonymous

    What is this for? FB.api(“me/likes/270801249647033″, function(response) {

  • Anonymous

    HI sanaullah, Its making a call to the graph api to get the user like on the particular page id (270801249647033). where page id – 270801249647033 belongs to webtuts. Hope its clear for you now.

  • Anonymous

    In your Scripts its already existed.. do i need to change with my page ID or leave it?

    As far as i experience I think I need to change this id..???

    Thanks,

  • Anonymous

    Yes you need to change with the page id of urs.

  • http://twitter.com/scriptholic Muhammad Azamuddin

    When a user already like the fan page, the download function doesn’t get called. why is that?

  • http://www.facebook.com/jupiterz S Osman Ali

    Hi,

    I am new developer. I want to know how can I use this code in my existing website which is based on HTML. I want when anyone is needed to download something it must press like button before that.

  • Anonymous

    HI azamuddin – It should work . Because wen document loads itself we check whether the user has liked our page or not.

  • Anonymous

    Just add the java scripting codes in the demo page in to ur html page(also jquery) , and change the page id to the page you want to like.

  • gmornob

    nice tutorial and script , thx for share

  • http://www.google.com/wripokfb Google

    Google…

    below you will discover the link to some websites that we assume you need to visit…

  • Overclokk

    Hi, Do I need to create any FB app for this script?

    Thanks :-)

  • Anonymous

    Hey , Yes you need to create one.Then only you will get the app id,which you will be using in the script

  • Overclokk

    Thanks for your fast reply :-)
    Does this app need any customization?

  • Anonymous

    Your app id has to be added plus the url of the page you want to be liked before file download should be replaced in the script.

  • Overclokk

    It works :-)
    I have try in local server, but now I have upload online and it’s working fine :-)
    Thanks a lot :-)

  • szuda

    Hi.
    How to modify your code to download always the file if the page has been liked.
    So I mean If the page is unliked and I after that I liked the page the download started… BUT if I close the page and after I open, the page still liked but the download not started.. How to modify? If the page is liked always download when I open the page.

  • Penter Yip

    Thank you for the script!!
    When I try the demo, once I liked the page, the file downloaded automatically. However, when I refresh the page, nothing will happen.

  • Anonymous

    accept

  • http://www.facebook.com/JMeloAco Jeison Melo

    i have the same problem how we can solved that?, thanks for your work

  • http://www.facebook.com/sarunathan.s Saru Nathan

    wen u refresh , and it wil check the page has been liked or not on document load, if u have liekd it , it will start download. some times browser prevents multiple downloads of same file, That might be your problem

  • nagi shupo

    Great script, can i use it with blogger? & so i have different files in different posts, how to apply this process?
    Thnx in advance

Ver peliculas online