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
$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);
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
$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);