9

好的。所以我不知道如何做到这一点,但你将不得不像一个 3 岁的孩子一样对我说话。我知道 PHP、HTML、CSS 和一点点 javascript。我希望能够创建一个页面,让用户使用 Facebook 并检查他们是否喜欢我的 Facebook 页面(https://www.facebook.com/MrDarrenGriffin)。如果他们有,重定向会将他们定向到一个页面。但是,如果没有,它会告诉他们要转到下载页面,他们必须喜欢该页面。点赞方法可以是代码中嵌入的点赞按钮。在他们喜欢该页面后,它将再次通过检查,如果他们成功喜欢我的页面,它会将他们重定向到下载部分(或指定页面)。

先谢谢了

4

2 回答 2

14

您可以使用此代码,因为它非常简单:

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

这 ll 用户user_likes权限

希望对你有帮助

于 2014-02-05T13:19:47.980 回答
9

Here are the steps to do so:

1) You need to use this step by step guide to connect user to your facebook page in order to fetch user basic 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) After knowing that user is connected using facebook you need to issue the graph GET request 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 (whether to take user to download page or other page)

Code from the tutorial above is given below too

<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? Goto http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Flikes%2F

This worked for me! :)

于 2013-06-11T14:44:51.010 回答