[Kakao] Kakao 계정으로 Login 하기[Kakao] Kakao 계정으로 Login 하기

Posted at 2020. 1. 31. 11:16 | Posted in API/Kakao
반응형




■ 카카오 계정으로 로그인 하기




# 소스코드

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=ege"/>

<meta nmae="viewport" content="user-scalable=no,inital-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,width=device-width">

<title>:: Custom Login Demo - Kakao JavaScript SDK ::</title>

<script type="text/javascript" src="https://developers.kakao.com/sdk/js/kakao.min.js"></script>

<script type="text/javascript">

    document.addEventListener("DOMContentLoaded", function() {


        // @details 카카오톡 Developer API 사이트에서 발급받은 JavaScript Key

        Kakao.init( "발급받은 JavaScript Key" );


        // @breif 카카오 로그인 버튼을 생성합니다.

        Kakao.Auth.createLoginButton({

              container : "#kakao-login-btn"

            , success : function( authObj ) {


                // console.log( authObj );


                Kakao.API.request({

                      url : "/v1/user/me"

                    , success : function( res ) {


                        // console.log( res );


                        // @breif 아이디

                        document.getElementById( "kakaoIdentity" ).innerHTMLres.id;


                        // @breif 닉네임

                        document.getElementById( "kakaoNickName" ).innerHTMLres.properties.nickname;


                        // @breif 프로필 이미지

                        document.getElementById( "kakaoProfileImg" ).srcres.properties.profile_image;


                        // @breif 썸네일 이미지

                        document.getElementById( "kakaoThumbnailImg" ).srcres.properties.thumbnail_image;


                    }, fail : function( error ) {

                        alert( JSON.stringify( error ) );

                    }

                });

            }

            , fail : function( error ) {

                alert( JSON.stringify( error ));

            }

        });

    });

</script>

</head>

<body>

    <div>카카오 아이디 : <span id="kakaoIdentity"></span></div>

    <div>닉네임 : <span id="kakaoNickName"></span></div>

    <div>프로필 이미지 : <img id="kakaoProfileImgsrc=""/></div>

    <div>썸네일 이미지 : <img id="kakaoThumbnailImgsrc=""/></div>

    <br/>

    <a id="kakao-login-btn"></a>

</body>

</html> 




# 출력결과







반응형

'API > Kakao' 카테고리의 다른 글

[Kakao] KakaoTalk으로 링크 공유하기 API  (5) 2018.08.31
//