Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Wook No.1

SNS 로그인(구글) 본문

Android

SNS 로그인(구글)

Wook No.1 2021. 6. 14. 16:54

구글 로그인

 

앱 등록 / API키 발급

developers.google.com/android/guides/client-auth

 

Authenticating Your Client  |  Google Play services  |  Google Developers

Certain Google Play services (such as Google Sign-in and App Invites) require you to provide the SHA-1 of your signing certificate so we can create an OAuth2 client and API key for your app. Using Play App Signing If you've published your app using Play Ap

developers.google.com

 

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