Referencethis example can be found in here <div> <button id="login">Login</button> <button id="logout">Logout</button> <button id="disconnect">Disconnect</button> </div> <div id="user-info" style="display: none;"></div> <div id="fb-root"></div> <script src="http://connect.facebook.net/zh_TW/all.js"></script> <script> // initialize the library with the API key FB.init({ apiKey : '34e097ae15eb987c288550a3d043e2b3' }); // fetch the status on load FB.getLoginStatus(handleSessionResponse); $('#login').bind('click', function() { FB.login(handleSessionResponse); }); $('#logout').bind('click', function() { FB.logout(handleSessionResponse); }); $('#disconnect').bind('click', function() { FB.api({ method : 'Auth.revokeAuthorization' }, function(response) { clearDisplay(); }); }); // no user, clear display function clearDisplay() { $('#user-info').hide('fast'); } var userid; var username; // handle a session response from any of the auth related calls function handleSessionResponse(response) { // if we dont have a session, just hide the user info if (!response.session) { clearDisplay(); return; } // if we have a session, query for the user's profile id and name FB.api({ method : 'fql.query', query : 'SELECT name, id FROM profile WHERE id=' + FB.getSession().uid // query data in http://developers.facebook.com/docs/reference/api/user/ }, function(response) { var user = response[0]; $('#user-info').html(user.id + user.name).show('fast'); userid = user.id; username = user.name; }); } function f() { $('#userid').attr("value", userid); $('#username').attr("value", username); } </script> |