3

I'm using facebook login on my webpage. At first login the facebook login app ask for permission to get user data.

There is any way to improve this to ask for permission of liking my facebook page too? And after user clicks, he would also like my facebook page.

Edit: My goal is to force people to like my facebook page if they want to login with facebook account to my page (not regular registration). For sure I would ask for permission to not violate terms of use. But would be nice if when they click on login and giving permission they would also like my fb page. So Facebook login and like wouldn't be seperated.

4

2 回答 2

1

当然,您刚刚将范围user_likes添加到 facebook 登录按钮。

您可以在此处阅读有关 facebook 登录按钮和范围属性的更多信息

现在您可以访问用户的喜欢,您可以检查用户是否喜欢您的页面,如果喜欢,只需将用户重定向到您的网站,如果不是,只需提示他喜欢您的页面,然后他才能访问您的其余部分网站。

这是一些代码,使用 Facebook Javascript SDK

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      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.statusChange', handleStatusChange);
    FB.Event.subscribe('edge.create', like);
  };

  // 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/pt_PT/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

然后在页面底部,放上这段javascript代码

<script>
    //this function is fired whenever the user presses the like button
    function like(response) {    
        if(response="https://www.facebook.com/YOUR_PAGE_USERNAME")
            //do something when the user likes your page, like redirect him, or something like that
    }
    //this function is fired everytime the page is loaded
    function handleStatusChange(response) {
        if (response.authResponse) {
            updateUserInfo(response);
        }
    }
    //this function is called by the function handleStatusChange and it checks everytime the page is loaded if the user already likes your page
    function updateUserInfo(response) {
        token = response.authResponse.accessToken;
        FB.api('/me/likes/YOUR_PAGE_ID', function(response) {
            if(response.data.length){
             //the user already likes your page 
            }
            else{
                //the user doesn'y like your page, or the user hasn't granted permission for you to access his likes. show him the like button
            }
        }, {access_token: token});

   }
</script>
于 2013-07-23T17:55:03.163 回答
0

您是否尝试过使用Facebook Like Box?如果是这样,你能解释为什么它不适合你的需要吗?

于 2013-07-23T17:49:40.433 回答