Hi,
When we try to call loginWithKakaoTalk and permission is not given to Kakao Talk application. There is no callback from Kakao Talk when permission is given and user is signed in. User comes to client application by pressing back button. When request comes back to client application is there any way to differentiate between below scenarios :
- User has given permission to Kakao Talk
- User has intentionally pressed back button
- User has not given permission to Kakao Talk
Below is code that I am using, please help how I can return callback in case of above scenario or how to handle above scenario as part of below code. Is there any other scenario that I need to handle as well :
Version used : group = “com.kakao.sdk.v2-user” 2.20.3
override fun login(activity: Activity, callback: KakaoLoginCallback) {
if (UserApiClient.instance.isKakaoTalkLoginAvailable(activity)) {
loginWithKakaoTalk(activity, callback)
} else {
loginWithKakaoAccount(activity, callback)
}
}
private fun loginWithKakaoTalk(
activity: Activity,
callback: KakaoLoginCallback
) {
UserApiClient.instance.loginWithKakaoTalk(activity) { token, error ->
if (error != null) {
println("Kakao : $error")
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
/*
This case comes when user has not given permission to Kakao talk .
After user given permission we will re-try to do Kakao Talk login.
*/
checkIfUserHasGivenPermissionToKakaoTalk(activity, callback)
} else {
/*
If there is any other error for Kakao Talk login we will fallback to Kakao
account login
*/
loginWithKakaoAccount(activity, callback)
}
} else if (token != null) {
callback.onKakaoLoginSuccess(token.accessToken)
}
}
}
private fun checkIfUserHasGivenPermissionToKakaoTalk(
activity: Activity,
callback: KakaoLoginCallback
) {
UserApiClient.instance.loginWithKakaoTalk(activity) { token, error ->
if (error != null) {
println("Kakao : $error")
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
callback.onKakaoLoginCancel()
} else {
/*
If there is any other error for Kakao Talk login we will fallback to Kakao
account login
*/
loginWithKakaoAccount(activity, callback)
}
}else if (token != null) {
callback.onKakaoLoginSuccess(token.accessToken)
}
}
}
private fun loginWithKakaoAccount(
activity: Activity,
callback: KakaoLoginCallback
) {
UserApiClient.instance.loginWithKakaoAccount(activity) { token, error ->
handleAccessToken(token, error, callback)
}
}
private fun handleAccessToken(token: OAuthToken?, error: Throwable?, callback: KakaoLoginCallback) {
if (error != null) {
handleAccessTokenError(error, callback)
} else if (token != null) {
callback.onKakaoLoginSuccess(token.accessToken)
}
}
private fun handleAccessTokenError(
error: Throwable?,
callback: KakaoLoginCallback
) {
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
callback.onKakaoLoginCancel()
} else {
if (error != null) {
callback.onKakaoLoginError(Exception(error.message))
}
}
}
문의 시, 사용하시는 SDK 버전 정보와 디벨로퍼스 앱ID를 알려주세요.
Faq 목록 - 10. Android ( Faq 목록 입니다 ) 먼저 확인해주세요.