Get FB User data via FQL


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <div id="fb-root"></div>
  2. <script src="http://connect.facebook.net/en_US/all.js"></script>
  3. <script type="text/javascript">
  4. FB.init({appId : '150545208302203', status : true, cookie : true});
  5. $(document).ready(function() {
  6. $('#facebook').bind('click', function() {
  7. FB.login(function(login_response){
  8. FB.api(
  9. {
  10. method: 'fql.query',
  11. query: 'SELECT first_name, last_name, sex, pic_big, birthday_date, email FROM user WHERE uid = ' + FB.getSession().uid
  12. },
  13. function(response) {
  14. var user = response[0];
  15. document.getElementById('UserFbId').value = FB.getSession().uid;
  16. document.getElementById('UserEmail').value = user.email;
  17. if(user.birthday_date != null) {
  18. user.birthday_date = user.birthday_date.split("/");
  19. if(user.birthday_date.length > 0) document.getElementById('UserDobMonth').value = user.birthday_date[0];
  20. if(user.birthday_date.length > 1) document.getElementById('UserDobDay').value = user.birthday_date[1];
  21. if(user.birthday_date.length > 2) document.getElementById('UserDobYear').value = user.birthday_date[2];
  22. }
  23. document.getElementById('UserName').value = user.first_name + ' ' + user.last_name;
  24. document.getElementById('UserFbThumbnail').value = user.pic_big;
  25. if(user.sex == 'male') {
  26. document.getElementById('UserGender').value = 'M';
  27. }
  28. else if(user.sex == 'female') {
  29. document.getElementById('UserGender').value = 'F';
  30. }
  31. document.getElementById('UserAddForm').submit();
  32. }
  33. );
  34. }, {perms:'publish_stream,email,user_birthday'});
  35. });
  36. });
  37. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.