In facebook connect, how can I check if a user is a fan of my facebook page? Is it possible to track?

后端 未结 3 1818
臣服心动
臣服心动 2020-12-30 17:55

I am trying to determine if a user is a facebook fan. I load the facebook JS library and initialize:



        
相关标签:
3条回答
  • 2020-12-30 18:29

    not sure if this is helpful at all, but I inspected the DOM with firebug and I found that it has moved onto the Facebook object

    var pageID = 'your page';
    var uid = FB.Facebook.apiClient.get_session().uid;
    FB.Facebook.apiClient.pages_isFan(pageID, uid, function(result){ alert("boo!");});
    
    0 讨论(0)
  • 2020-12-30 18:32

    Please note that @daaku's answer is true only in two cases:

    1. If your app grant the user_likes permission or
    2. The user's pages privacy setting is set to everyone.

    Source:

    Note: This call no longer requires a session key. You must pass a user ID if you don't pass a session key. If the user's pages are set to less than everyone privacy, you must ask the user for the user_likes extended permission and include a valid user access token in the API call.

    Try this code to better understand:

    <button onclick="checkDoesLike()">Check if user Likes the Page (wrong way)</button>
    <button onclick="checkDoesLike2()">Check if user Likes the Page (right way)</button>
    
    <script>
    window.checkDoesLike = function() {
      FB.api({ method: 'pages.isFan', page_id: '184484190795', uid: '579187141' }, function(resp) {
        if (resp) {
          Log.info('579187141 likes the Application.');
        } else {
          Log.error("579187141 doesn't like the Application.");
        }
      });
    };
    
    window.checkDoesLike2 = function() {
      FB.api({ method: 'pages.isFan', page_id: '184484190795', uid: '579187141' }, function(resp) {
        if (resp == true) {
          Log.info('579187141 likes the Application.');
        } else if(resp.error_code) {
          Log.error(resp.error_msg);
        } else {
          Log.error("579187141 doesn't like the Application.");
        }
      });
    };
    </script>
    

    Working example.

    I've also written a full tutorial about this today.

    0 讨论(0)
  • 2020-12-30 18:40

    Using the new JS SDK:

    <fb:login-button perms="user_likes">
      Grant Permissions to Allow access to Likes
    </fb:login-button>
    
    <button onclick="checkDoesLike()">Check if user Likes the Page</button>
    
    <h1>Like this Application's Page</h1>
    <fb:like-box profile-id="184484190795"></fb:like-box>
    
    <script>
    window.checkDoesLike = function() {
      FB.api({ method: 'pages.isFan', page_id: '184484190795' }, function(resp) {
        if (resp) {
          Log.info('You like the Application.');
        } else {
          Log.error("You don't like the Application.");
        }
      });
    };
    </script>
    

    A working example: http://fbrell.com/fb.api/does-like

    0 讨论(0)
提交回复
热议问题