Facebook API FB.getLoginStatus returns undefined

I have added a like button on my website, and want to know who clicked the like button. These are my sample code:

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({appId: '182722795115444', status: true, cookie: true,
                 xfbml: true});

        // To find who clicked the like button
        FB.Event.subscribe('edge.create', function(response){
            FB.getLoginStatus(function(response) {

                if (response.session) {
                    // logged in and connected user, someone you know
                    alert("logged in and connected user");
                } else {
                    // no user session available, someone you dont know
                    alert("no user session available");
                }
            });
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
    <script src="http://connect.facebook.net/en_US/all.js#appId=182722795115444&amp;xfbml=1"></script>
    <fb:like href="www.blogcountry.net" send="true" width="450" show_faces="true" font=""></fb:like>

When I clicked the Like button, and login facebook, do like successfully, but got "no user session available" alert.

So I am confused:

  • My appId in FB.init is the same as fb:like tag, is it right?
  • Are there something wrong in my program ?
  • How to get user name who click the Like button?
  • Thanks in advance.


    Update:

    @OffBySome Thanks for your answer.

    You means I must call FB authenticate API, then I could get the user's info? But...in facebook development doc FAQ:


    How do I know when a user clicks a Like button?

    If you are using the XFBML version of the button, you can subscribe to the 'edge.create' event through FB.Event.subscribe.


    So, It means I cannot know who clicks the Like Button, just know the button is clicked.

    If I want to get user's info, I must implement the login action before click Like? It's really bad userbility.

    Could anyone give a good idea to resolve it...


    I am pretty sure you won't get a Facebook session just by liking a page. You normally only get a user Facebook session when they authenticate with your application (for example, with <fb:login-button autologoutlink="true"></fb:login-button> ) . If do an an alert(JSON.stringify(response)); inside that function what values do you get?


    尝试这个..

    FB.Event.subscribe('edge.create', function(href, widget) 
    {                   
    alert('You just liked '+href);  
    
        session = FB.getSession();
        uid = session['uid'];
        alert(uid);
    
    });
    

    Had the same problem today, this thread solved it for me - FB.getLoginStatus inside edge.create callback is returning unknown status and null session after logging in from the popup

    There is second parameter to the FB.getLoginStatus method that must be set to 'true'

    链接地址: http://www.djcxy.com/p/6082.html

    上一篇: 邮编查找API?

    下一篇: Facebook API FB.getLoginStatus返回未定义