Kakaotalk算是韩国国民级别的APP,只要做韩国移动APP,少不了Kakaotalk三方登录
IOS开发文档:https://developers.kakao.com/docs/latest/en/kakaologin/ios
安卓开发文档:https://developers.kakao.com/docs/latest/en/kakaologin/android
安卓接入步骤:
1.老步骤,引入sdk
You need to set Gradle by declaring a Maven repository to sync your project with the Android SDK. Depending on the version of Android Studio, how you declare repositories is different.
If you use Android Studio Arctic Fox, declare the Maven repository in dependencyResolutionManagement
in the project-level settings.gradle file. For more information, refer to Centralizing repositories declaration.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' }
}
}
If you use an earlier version of Android Studio Arctic Fox, declare the Maven repository in allprojects
in the project-level build.gradle file.
// NOTE: You cannot declare repositories through 'allprojects' in Android Studio Arctic Fox.
allprojects {
repositories {
google()
jcenter()
maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/'}
}
}
dependencies {
implementation "com.kakao.sdk:v2-all:2.11.0" // Add all modules (Available in 2.11.0 or higher)
implementation "com.kakao.sdk:v2-user:2.11.0" // Kakao Login
implementation "com.kakao.sdk:v2-talk:2.11.0" // Kakao Talk Social, Kakao Talk messaging
implementation "com.kakao.sdk:v2-friend:2.11.0" // Friend picker
implementation "com.kakao.sdk:v2-story:2.11.0" // Kakao Story
implementation "com.kakao.sdk:v2-share:2.11.0" // Kakao Talk sharing
implementation "com.kakao.sdk:v2-navi:2.11.0" // Kakao Navi
}
官方文档给出的最新版本2.11.0 但是引入项目一直报错,无奈只能找老版本
最后测试2.5.3版本可用
implementation "com.kakao.sdk:v2-user:2.5.3"
2.接下来就是一些基本的配置,要有网络权限,用的还是Java8
// Use Java 8 features
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// For Kotlin projects
kotlinOptions {
jvmTarget = "1.8"
}
}
正式环境,千万别忘了加混淆:
Configure for shrinking and obfuscation (Optional)
If you enable shrinking, obfuscation, and optimization when buiding the release version of your app, add the following -keep lines in the ProGuard rules file to exclude the Kakao SDK from shrinking and obfuscation.
-keep class com.kakao.sdk.**.model.* { <fields>; }
-keep class * extends com.google.gson.TypeAdapter
3.还是常规步骤:初始化SDK
Initialize SDK
After installing the SDK, you need to initialize the SDK for initial setup.
Initialize the KakaoSDK
instance by adding the init
method in the Application
instance with your Native app key.
class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()
// Other codes for initialization
// Initialize Android SDK
KakaoSdk.init(this, "${YOUR_NATIVE_APP_KEY}")
}
}
4.开始接入登录逻辑:
fun onKaKaoTalkClicked() {
if (UserApiClient.instance.isKakaoTalkLoginAvailable(requireContext())) {
UserApiClient.instance.loginWithKakaoTalk(requireContext()) { token, error ->
if (error != null) {
LoggerUtils.loginKaKaoToken("failed")
CustomMiddleToast.showShort(error.message)
} else if (token != null) {
thirdLogin(ThirdLoginBody.KAKAO, token.accessToken, null)
LoggerUtils.loginKaKaoToken("success")
}
}
} else {
CustomMiddleToast.showShort(ResourceUtil.getString(R.string.login_error_toast_no_kakao))
}
}
注意:KakaoTalk SDK 提供了一个 :isKakaoTalkLoginAvailable() 函数,可以检测手机是否安装了Kakao和检测有没有安装上未登录等,如果合适登录,可以拿到一个kakao token 然后将token 传给server,后端通过api可以获取到kakao的user info 但是kakao 不像google Facebook 拿不到user_id