본문 바로가기

API

facebook 로그인 연동 소스 (javascript+asp classic)

로그인 버튼 <SCRIPT language=javascript> window.fbAsyncInit = function(){ FB.init({ appId: '앱 아이디', status: true, cookie: true, xfbml: true, oauth: true}); } function updateButton(response) { var button = document.getElementById('fb-auth'); if (response.authResponse) { FB.api('/me', function(response) { if(confirm('facebookID:'+response.email+' 로 로그인하시겠습니까?')==true){ // 확인을 선택했을 경우의 처리. 이 예제에서는 페이스북으로부터 넘겨받은 값들을 post로 다른 페이지에 전달하고 있음. form 생성 및 서브밋은 jquery로.. var $form = $('
'); $form.attr('action', 'test_ok.asp'); $form.attr('method', 'post'); $form.attr('target', 'iFrm'); // 타겟은 임의로 지정함 $form.appendTo('body'); var fuid = $(''); var fname = $(''); var fsex = $(''); var ffirst_name = $(''); var flast_name = $(''); var flocale = $(''); var fbirthday = $(''); $form.append(fuid).append(fname).append(fsex).append(ffirst_name).append(flast_name).append(flocale).append(fbirthday); $form.submit(); }else{ // 취소를 선택했을 경우의 처리(아래는 페이스북 로그아웃 처리) FB.logout(function(response) { }); } }); } else { FB.login(function(response) { if (response.authResponse) { FB.api('/me', function(response) { }); } else { } }, {scope:'email'}); } } document.getElementById('fb-auth').onclick = function() { FB.Event.subscribe('auth.statusChange', updateButton); FB.getLoginStatus(updateButton); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/ko_KR/all.js'; document.getElementById('fb-root').appendChild(e); }()); </SCRIPT>

오늘 업무 관련해서 직접 테스트해본 소스이므로, 현 시점에서 무조건 정상 작동하는 소스입니다.

(물론 소스 그대로 가져다 사용하시면 에러...중간에 예제로 넣어놓은 jquery 소스등이 포함되어 있으므로..

 아 그냥...jquery 뺀 "그대로 복사해도 무조건 에러 안나는 소스로 아래 따로 넣겠습니다. 물론 app id는 적어주셔야겠구요.)

로그인 버튼 <SCRIPT language=javascript> window.fbAsyncInit = function(){ FB.init({ appId: '앱 아이디', status: true, cookie: true, xfbml: true, oauth: true}); } function updateButton(response) { var button = document.getElementById('fb-auth'); if (response.authResponse) { FB.api('/me', function(response) { if(confirm('facebookID:'+response.email+' 로 로그인하시겠습니까?')==true){ // 확인을 선택했을 경우의 처리. }else{ // 취소를 선택했을 경우의 처리(아래는 페이스북 로그아웃 처리) FB.logout(function(response) { }); } }); } else { FB.login(function(response) { if (response.authResponse) { FB.api('/me', function(response) { }); } else { } }, {scope:'email'}); } } document.getElementById('fb-auth').onclick = function() { FB.Event.subscribe('auth.statusChange', updateButton); FB.getLoginStatus(updateButton); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/ko_KR/all.js'; document.getElementById('fb-root').appendChild(e); }()); </SCRIPT>

참고사항으로 test_ok.asp 파일에서 값 받아서 출력해주는 소스

<%
	fuid = trim(request.form("fuid"))
	fname = trim(request.form("fname"))
	fsex = trim(request.form("fsex"))
	ffirst_name = trim(request.form("ffirst_name"))
	flast_name = trim(request.form("flast_name"))
	flocale = trim(request.form("flocale"))
	fbirthday = trim(request.form("fbirthday"))
%>
아이디 : <%=fuid%>
이름 : <%=fname%>
성별 : <%=fsex%>
퍼스트네임 : <%=ffirst_name%>
라스트네임 : <%=flast_name%>
지역 : <%=flocale%>
생일 : <%=fbirthday%>

'API' 카테고리의 다른 글

페이스북 공유하기 연동시 내용 및 사진 갱신 안될때  (0) 2013.07.22