Login
Status:
unknown
|
Disconnect
|
Logout
<h1>Login, Logout, Name and Profile Picture</h1> <div id="account-info"></div> <script> /** * This assumes the user is logged in and renders their profile picture, * name and a logout link. */ function showAccountInfo() { FB.api( { method: 'fql.query', query: 'SELECT name, pic_square FROM user WHERE uid='+FB.getUserID() }, function(response) { Log.info('API Callback', response); document.getElementById('account-info').innerHTML = ( '<img src="' + response[0].pic_square + '"> ' + response[0].name + ' <img onclick="FB.logout()" style="cursor: pointer;"' + 'src="https://s-static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">' ); } ); } /** * This assumes the user is logged out, and renders a login button. */ function showLoginButton() { document.getElementById('account-info').innerHTML = ( '<img onclick="FB.login()" style="cursor: pointer;"' + 'src="https://s-static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">' ); } /** * This will be called once on page load, and every time the status changes. */ function onStatus(response) { Log.info('onStatus', response); if (response.status === 'connected') { showAccountInfo(); } else { showLoginButton(); } } FB.getLoginStatus(function(response) { onStatus(response); // once on page load FB.Event.subscribe('auth.statusChange', onStatus); // every status change }); </script>
Examples
Run Code
Clear