정미나닷컴

[JavaScript] Facebook 연동, 회원 정보 가져오기 본문

IT

[JavaScript] Facebook 연동, 회원 정보 가져오기

정미나 2012. 4. 9. 16:16

FB.getLoginStatus(function(c) {
   if (response.authResponse) {
      document.f_regist.acc_token.value = response.authResponse.accessToken;
      FB.api('/me', function(response) {
         document.f_regist.email.value = response.email;
         document.f_regist.first_name.value = response.first_name;
         document.f_regist.last_name.value = response.last_name; 
         if(response.gender == "female") {
            document.f_regist.sex[0].checked = true;
         } else {
            document.f_regist.sex[1].checked = true;
         }
     
         var arr_birth = response.birthday.split("/");
         if(arr_birth.length == 3) {
            var b_month = document.getElementById("b_month");
            var i=0;
            for (i=0; i<b_month.options.length; i++){
               if (b_month.options[i].value == arr_birth[0]){
                  b_month.selectedIndex = i;
                  break;
               }
            }
          
           var b_day = document.getElementById("b_day");
           for (i=0; i<b_day.options.length; i++){
              if (b_day.options[i].value == arr_birth[1]){
                 b_day.selectedIndex = i;
                 break;
              }
           }
          
           var b_year = document.getElementById("b_year");
           for (i=0; i<b_year.options.length; i++) {
              if (b_year.options[i].text == arr_birth[2]) {
                 b_year.selectedIndex = i;
                 break;
              }
           }
        }
     }); 

 

  }else{

     FB.login(function(response) {
        if (response.authResponse) {   
           document.f_regist.acc_token.value = response.authResponse.accessToken;
           FB.api('/me', function(response) {
              document.f_regist.email.value = response.email;
              document.f_regist.first_name.value = response.first_name;
              document.f_regist.last_name.value = response.last_name; 
              if(response.gender == "female") {
                 document.f_regist.sex[0].checked = true;
              } else {
                 document.f_regist.sex[1].checked = true;
              }
      
              var arr_birth = response.birthday.split("/");
              if(arr_birth.length == 3) {
                 var b_month = document.getElementById("b_month");
                 var i=0;
                 for (i=0; i<b_month.options.length; i++){
                    if (b_month.options[i].value == arr_birth[0]){
                       b_month.selectedIndex = i;
                       break;
                    }
                 }
           
                 var b_day = document.getElementById("b_day");
                 for (i=0; i<b_day.options.length; i++){
                    if (b_day.options[i].value == arr_birth[1]){
                       b_day.selectedIndex = i;
                       break;
                    }
                 }
           
                 var b_year = document.getElementById("b_year");
                 for (i=0; i<b_year.options.length; i++){
                    if (b_year.options[i].text == arr_birth[2]){
                       b_year.selectedIndex = i;
                       break;
                    }
                 }
              }
           });
        }
     }, {
        scope : 'email,user_likes,user_birthday'
     });

   }

})