Check if the logged in user liked my Facebook page

OK Therefore, I have no idea how to do this, but you will have to talk to me as 3 years. I know PHP, HTML, CSS and tiny jidgecript. I want to be able to make a page that receives facebook users and checks if they liked my Facebook page ( https://www.facebook.com/MrDarrenGriffin ). If they are, a redirect will direct them to the page. However, if not, he will tell them that go to the download page, they will like the page. The sympathy method can be with a built-in button in the code. After they liked the page, she will check the check again and if they like my page, she will redirect them to the download section (or to the specified page).

Thanks in advance: D

+9
facebook facebook-like
source share
2 answers

Here are the steps for doing this:

1) You need to use this walkthrough to connect the user to your facebook page in order to get basic user information

https://developers.facebook.com/docs/facebook-login/getting-started-web/

FB.api('/me', function(response) { console.log('Good to see you, ' + response.name + '.'); } 

2) Upon learning that the user is connected via facebook, you need to issue a GET request to the graph to find out about this user that he liked your page or not.

 FB.api('/me/likes/YOUR_APP_ID', function(response) { console.log(response.data); } 

3) And then run your business logic (do you need to load a page or another page)

The code from the above guide is given below.

 <body> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId : 'YOUR_APP_ID', // App ID channelUrl : '//www.example.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('auth.authResponseChange', function(response) { if (response.status === 'connected') { testAPI(); } else if (response.status === 'not_authorized') { $("#btnFB").show(); FB.login(); } else { $("#btnFB").show(); FB.login(); } }); 

};

 // Load the SDK asynchronously (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); function testAPI() { FB.api('/me', function(response) { console.log('Good to see you, ' + response.name + '.'); }); FB.api('/me/likes/PAGE_ID', function(response) { console.log(response.data); }); } 

How to get PAGE_ID? Go to http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Flikes%2F

It worked for me! :)

+8
source share

You can use this code because it is so simple:

 FB.api({ method: "pages.isFan", page_id: page_id, }, function(response) { console.log(response); if(response){ alert('You Likey'); } else { alert('You not Likey :('); } } ); 

this is user permission user_likes

Hope this helps you

+14
source share

All Articles