페이지 이동경로
  • Docs>
  • Kakao Sync

Kakao Sync

Auto-login from Kakao Talk

This document contains how to implement the Auto-login function using the Legacy SDK for Android and iOS. The latest SDK does not support this function.

For more details, refer to Concepts.

Legacy Android

For Auto-login, add auto_login to extraParams, and set it to true. The auto_login parameter should be Map type, and use the constants only supported by com.kakao.auth.StringSet as values.

Set AuthType to KAKAO_TALK_ONLY because Auto-login only works from the Kakao Talk in-app browser.

If a user successfully logs in, the user is redirected to a service page in a logged-in state.

import com.kakao.auth.StringSet;

public class SampleLoginActivity extends BaseActivity {
    private SessionCallback callback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sample_login);

        callback = new SessionCallback();
        Session.getCurrentSession().addCallback(callback); // Add callback

        Map<String, String> extraParams = new HashMap<>();
        extraParams.put(StringSet.auto_login, "true");

        Session.getCurrentSession().open(AuthType.KAKAO_TALK_ONLY, this, extraParams); // Pass KAKAO_TALK_ONLY as a parameter. Otherwise, the webView login is executed if Kakao Talk has not installed.  
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (Session.getCurrentSession().handleActivityResult(requestCode, resultCode, data)) {
            return;
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Session.getCurrentSession().removeCallback(callback); // Remove callback
    }

    private class SessionCallback implements ISessionCallback {

        @Override
        public void onSessionOpened() {
            // Login success
        }

        @Override
        public void onSessionOpenFailed(KakaoException exception) {
            // Login fail
        }
    }
}

Legacy iOS

To use the Auto-login feature, you need to call canOpenURL that checks if Kakao Talk has been installed, and set authType to KOAuthType.talk. After that, pass KOSessionAutoLoginParameterKey as parameters.

// Check if Kakao Talk has been installed
if UIApplication.shared.canOpenURL(URL(string: "kakaokompassauth://")!) {

    // For Auto-login, add `KOSessionAutoLoginParameterKey`
    let parameters = [KOSessionAutoLoginParameterKey: "true"]

    // Simple login without a dialog to choose a login method 
    let authTypes = [NSNumber(value: KOAuthType.talk.rawValue)]

    // Proceed login
    KOSession.shared()?.open(completionHandler: { (error) in

        if error != nil {
            // Change to a logged-in state

        } else {
            // If login fails or other error occurs, Auto-login is not available.
        }

    }, parameters: parameters, authTypes: authTypes)

} else {
    // If Kakao Talk has not been installed, Auto-login is not available.
}

Considering the Auto-login is only available in the Kakao Talk in-app browser, you need to handle an error exception by showing the user the service page in a logged-out state if Kakao Talk has not been installed on the user's device. There is also the error exception that a user has not yet signed up for KaKao Talk. In this situation, you need to handle the expectation as you would a logged-out state.

See more

Android

iOS