Wook No.1
SNS 로그인(구글) 본문
구글 로그인
앱 등록 / API키 발급
developers.google.com/android/guides/client-auth
Gradle
dependencies {
implementation 'com.google.android.gms:play-services-auth:19.0.0'
}
Google Sign In API / 클라이언트 설정 및 생성
val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(context.getString(R.string.default_web_client_id))
.requestEmail()
.build()
googleSignInClient = GoogleSignIn.getClient(this@Activity), googleSignInOptions)
로그인 요청
startActivityForResult(googleSignInClient?.signInIntent, GOOGLE_SIGN_IN)
Callback
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, requestCode, data)
if(GOOGLE_SIGN_IN == requestCode) {
try {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
if (task.isSuccessful) {
val acct = task.getResult(ApiException::class.java)
// TODO login success acct.idToken
}
} catch (e: ApiException) {
e.printStackTrace()
}
}
}
'Android' 카테고리의 다른 글
SNS 로그인(애플) #2 (0) | 2021.06.21 |
---|---|
SNS 로그인(애플) #1 (0) | 2021.06.17 |
SNS 로그인(카카오) (0) | 2021.06.14 |
SNS 로그인(네이버) (0) | 2021.06.14 |
Webview iFrame 안에서 Pull To Refresh 이슈 대응 (0) | 2021.06.07 |
Comments