检查登录用户是否喜欢我的Facebook页面

9 facebook facebook-like

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

提前致谢

sim*_*yos 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 :(');
        }
    }
);
Run Code Online (Sandbox Code Playgroud)

这个ll用户user_likes权限

希望对你有帮助


wak*_*med 9

以下是执行此操作的步骤:

1)您需要使用此分步指南将用户连接到您的Facebook页面,以获取用户的基本信息

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

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

2)在知道用户使用Facebook连接后,您需要发出图表GET请求以了解该用户是否喜欢您的页面

FB.api('/me/likes/YOUR_APP_ID', function(response) {
    console.log(response.data);
}
Run Code Online (Sandbox Code Playgroud)

3)然后运行您的业务逻辑(是否带用户下载页面或其他页面)

上面的教程中的代码也在下面给出

<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();
    }
});
Run Code Online (Sandbox Code Playgroud)

};

// 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);
  });
}
Run Code Online (Sandbox Code Playgroud)

如何获得PAGE_ID?转到http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Flikes%2F

这对我有用!:)