1. $(window).load(function(){
  2. login();
  3. });
  4.  
  5. var login = function(){
  6. FB.login(function(response) {
  7. if (response.authResponse) {
  8. console.log('Welcome! Fetching your information.... ');
  9. get_fb_info();
  10. } else {
  11. console.log('User cancelled login or did not fully authorize.');
  12. }
  13. }, {scope: 'user_about_me, friends_about_me, user_activities, friends_activities, user_birthday, friends_birthday, user_checkins, friends_checkins, user_education_history, friends_education_history, user_events, friends_events, user_groups, friends_groups, user_hometown, friends_hometown, user_interests, friends_interests, user_likes, friends_likes, user_location, friends_location, user_notes, friends_notes, user_photos, friends_photos, user_questions, friends_questions, user_relationships, friends_relationships, user_relationship_details, friends_relationship_details, user_religion_politics, friends_religion_politics, user_status, friends_status, user_subscriptions, friends_subscriptions, user_videos, friends_videos, user_website, friends_website, user_work_history, friends_work_history, email, read_friendlists, read_insights, read_mailbox, read_requests, read_stream, xmpp_login, ads_management, create_event, manage_friendlists, manage_notifications, user_online_presence, friends_online_presence, publish_checkins, publish_stream, rsvp_event, publish_actions, user_actions.music, friends_actions.music, user_actions.news, friends_actions.news, user_actions.video, friends_actions.video, user_actions:ssiz-three, friends_actions:ssiz-three, user_games_activity, friends_games_activity, manage_pages'});
  14. }
  15.  
  16. <fb:login-button show-faces="true" width="200" max-rows="1" scope="user_about_me...">
  17. </fb:login-button>
  18.  
  19. $user = null; //facebook user uid
  20. try{
  21. include_once 'fb-php/src/facebook.php';
  22. }
  23. catch(Exception $o){
  24. echo '<pre>';
  25. print_r($o);
  26. echo '</pre>';
  27. }
  28. // Create our Application instance.
  29. $facebook = new Facebook(array(
  30. 'appId' => 'YOUR APP ID',
  31. 'secret' => 'YOUR SECRET ID',
  32. 'cookie' => true,
  33. ));
  34.  
  35. //Facebook Authentication part
  36. $user = $facebook->getUser();
  37. $loginUrl = $facebook->getLoginUrl(
  38. array(
  39. 'scope' => 'email,publish_stream,user_photos'
  40. )
  41. );
  42.  
  43. if ($user) {
  44. try {
  45. // Proceed knowing you have a logged in user who's authenticated.
  46. $user_profile = $facebook->api('/me');
  47. } catch (FacebookApiException $e) {
  48. //you should use error_log($e); instead of printing the info on browser
  49. d($e); // d is a debug function defined at the end of this file
  50. $user = null;
  51. }
  52. }
  53.  
  54. if (!$user) {
  55. echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
  56. exit;
  57. }