检查登录用户是否喜欢我的Facebook页面 [英] Check if logged in user has liked my Facebook Page

查看:127
本文介绍了检查登录用户是否喜欢我的Facebook页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



提前感谢:D

解决方案

以下是执行步骤:



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



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

  FB.api('/ me',function(response){
console。 log('很高兴见到你'+ response.name +'。');
}

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

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

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



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

 <身体GT; 
< 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,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true / /解析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();
}
});

};

 code> //异步加载SDK 
(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);
});
}



/ p>

如何获取PAGE_ID?
转到 http://开发人员。 facebook.com/tools/explorer/?method=GET&path=me%2Flikes%2F



这对我有用! :)


OK. So I have no idea on how to do this but you are going to have to talk like a 3 year old to me. I know PHP, HTML, CSS and a tiny smidge of javascript. I want to be able to make a page that gets the users facebook and checks to see if they have liked my Facebook page (https://www.facebook.com/MrDarrenGriffin). If they have, a redirect will direct them to a page. However, If not, it will tell them that to go to the downloads page, they have to like the page. The liking method could be with the embedded like button in the code. After they have liked the page it will go through the check again and if they have successfully liked my page, it will redirect them to the downloads section (or a specified page).

Thanks in advance :D

解决方案

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! :)

这篇关于检查登录用户是否喜欢我的Facebook页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆