Test TAM
  • Kakao Javascript SDK v1 Test
  • Kakao Javascript SDK v2 Test
  • 프로필 가져오기

    • JavaScript
    • PHP

    Response
    
    Kakao.init('{JAVASCRIPT_KEY}'); //★ 수정 할 것 : SDK를 초기화 합니다. 사용할 앱의 JavaScript 키를 설정해 주세요.
    console.log(Kakao.isInitialized()); // SDK 초기화 여부를 판단합니다.
    
    function loginWithKakaoPopUp() {
        Kakao.Auth.login({
            success: function(authObj) {
                document.getElementById("Response").innerText = JSON.stringify(authObj);
                Kakao.Auth.setAccessToken(authObj.access_token);
            },
            fail: function(err) {
                document.getElementById("Response").innerText = JSON.stringify(err);
            },
        })
    }
    
    function talkProfileWithKakao() {
        Kakao.API.request({
            url: '/v1/api/talk/profile',
            success: function(response) {
                document.getElementById("Response").innerText = JSON.stringify(response);
                document.getElementById("talk_nickname").innerText = response.nickName;
                document.getElementById("talk_profile_image").src = response.profileImageURL;
                document.getElementById("talk_thumbnail_image").src = response.thumbnailURL;
                document.getElementById("talk_countryISO").innerText = response.countryISO;
            },
            fail: function(error) {
                document.getElementById("Response").innerText = error;
            }
        });
    }
                            
    
    
    
    
    

    Response

    scope=talk_message,friends

    GET kapi.kakao.com/v1/api/talk/profile HTTP/1.1 Authorization: Bearer {ACCESS_TOKEN}
    string(62) "{"msg":"access token should not be null or empty","code":-401}"
    
    $url = "https://kapi.kakao.com/v1/api/talk/profile";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $header = "Bearer " . $_SESSION["accessToken"];
    $headers = array();
    $headers[] = "Authorization: " . $header;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $res = curl_exec($ch);
    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
                            
  • 친구 목록 가져오기

    • JavaScript
    • PHP

    Response
    
    function talkFriendListAuthorizeWithKakao() {
        Kakao.Auth.login({
            scope: 'talk_message,friends',
            success: function(response) {
                console.log(response);
            },
            fail: function(error) {
                console.log(error);
            }
        });
    }
    
    function talkFriendListWithKakao() {
        Kakao.API.request({ 
            url: '/v1/api/talk/friends',
            success: function(response) {
                console.log(response);
                document.getElementById("friend_list").innerText = JSON.stringify(response);
            },
            fail: function(error) {
                console.log(error);
            }
        });
    }
                            
    
    
    
    

    Response

    GET kapi.kakao.com/v1/api/talk/friends HTTP/1.1 Authorization: Bearer {ACCESS_TOKEN}

    Warning: Invalid argument supplied for foreach() in /hosting/leedongha/html/kakao_talk_social.php on line 311
    string(62) "{"msg":"access token should not be null or empty","code":-401}"
    
    $url = "https://kapi.kakao.com/v1/api/talk/friends";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $header = "Bearer " . $_SESSION["accessToken"];
    $headers = array();
    $headers[] = "Authorization: " . $header;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $res = curl_exec($ch);
    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);