KakaoTalk

KakaoTalk API refers to KakaoTalk service offered as API. This only works in an app that has Kakao account login function and only with users who have linked their KakaoTalk with kakao account.

Below are KakaoTalk API supported currently.

Before getting started

1. Confirm App-setting which enables you to use login API. refer to loginbase 템플릿.

2. Check if you have set Key that has been used by App sign in setting > general > platform > Android > Key-hash.

On procedures regarding how to make key hash, please refer to part.2 of Create App.

Getting started

Request API by using KakaoTalkService. Send callback, KakaoTalkHttpResponseHandler as a result of API request using parameter. Refer example below and implement KakaoTalkHttpResponseHandler,

public class KakaoTalkMainActivity extends Activity {

    private void redirectLoginActivity() {
        final Intent intent = new Intent(this, KakaoTalkLoginActivity.class);
        startActivity(intent);
        finish();
    }

    private abstract class MyTalkHttpResponseHandler<T> extends KakaoTalkHttpResponseHandler<T> {
        @Override
        protected void onHttpSessionClosedFailure(final APIErrorResult errorResult) {
            redirectLoginActivity();
        }

        @Override
        protected void onNotKakaoTalkUser(){
            Toast.makeText(getApplicationContext(), "not a KakaoTalk user", Toast.LENGTH_SHORT).show();
        }

        @Override
        protected void onFailure(final APIErrorResult errorResult) {
            Toast.makeText(getApplicationContext(), "failed : " + errorResult, Toast.LENGTH_SHORT).show();
        }
    }
}

You can confirm on why API request failed through received parameter as APIErrorResult#getErrorCode()), APIErrorResult#getErrorMessage()). Following errors could be returned upon KakaoTalk API call.

Profile request

Requesting profile is only allowed for users who have linked their kakao account with KakaoTalk. In order to use this functionality , User token is needed which can be retrieved from successful login.

Below are the information which can be retrieved from KakaoTalk profile API.

  • KakaoTalk Nickname info (nickName)
  • KakaoTalk Profile image URL (profileImageURL)
  • KakaoTalk Profile image thumbnail URL (thumbnailImageURL)
  • KakaoTalk Country code (countryISO)

Following is an example for requesting Kakaotalk profile. when requesting KakaoTalkService#requestProfile(KakaoTalkHttpResponseHandler<KakaoTalkProfile>) is succeeded, KakaoTalkProfile will be shown as a result. If you want to receive image in https url, request KakaoTalkService.html#requestProfile(KakaoTalkHttpResponseHandler<KakaoTalkProfile>, Boolean) API.

public void readProfile() {
    KakaoTalkService.getInstance().requestProfile(new MyTalkHttpResponseHandler<KakaoTalkProfile>() {
        @Override
        protected void onHttpSuccess(final KakaoTalkProfile talkProfile) {
              final String nickName = talkProfile.getNickName();
              final String profileImageURL = talkProfile.getProfileImageURL();
              final String thumbnailURL = talkProfile.getThumbnailURL();
              final String countryISO = talkProfile.getCountryISO();
              // display
        }
    }
}

For details about MyTalkHttpResponseHandler, refer Before getting started


Last Modified : 2018-03-19