0

내 안드로이드 응용 프로그램에 Facebook과 Google 인증을 통합하려고합니다. 응용 프로그램을 실행하는 동안 사용자가 Facebook 또는 Google 인증을 사용하여 응용 프로그램에 로그온했는지 확인하고 싶습니다. 아래 코드를 사용하여 Facebook에서 성공했습니다.사용자가 Google 계정으로 로그인했는지 확인하는 방법

if (Profile.getCurrentProfile() != null && AccessToken.getCurrentAccessToken() != null){ 
     Intent i = new Intent(Splash.this, SecondActivity.class); 
     startActivity(i); 
     finish(); 
} 

Google에서는 성공하지 못했습니다. 또한 많은 답변을 검색했지만 대부분은 Google 인증을 위해 Firebase를 사용하고있었습니다.

어떻게 Google 인증을 사용하고 Firebase를 사용하지 않고이 작업을 수행 할 수 있습니까?

도움을 받으실 수 있습니다. 미리 감사드립니다.

+0

GoogleSignInApi의 silentSignIn 메소드는 사용자의 캐시 된 신임 정보의 유효성을 검사하는 데 사용할 수 있습니다. –

+0

@SudheeshR 조금 더 자세히 설명해 주시겠습니까? –

+0

GoogleSignInApi.silentSignIn() 메소드를 사용하여 로그인 자격 증명이 유효한지 확인할 수 있습니다. 자격 증명의 유효성을 검사하는 데 사용되는 OptionalPendingResult 개체를 반환합니다. 신임장이 유효하면 OptionalPendingResult의 isDone() 메소드가 true를 리턴합니다. 그런 다음 get 메소드를 사용하여 즉시 결과를 얻을 수 있습니다 (사용 가능한 경우). GoogleSignInApi에 대한 –

답변

0
@Override 
    public void onStart() { 
     super.onStart(); 

     OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); 
     if (opr.isDone()) { 
      // If the user's cached credentials are valid, the OptionalPendingResult will be "done" 
      // and the GoogleSignInResult will be available instantly. 
      Log.d(TAG, "Got cached sign-in"); 
      GoogleSignInResult result = opr.get(); 
      handleSignInResult(result); 
     } else { 
      // If the user has not previously signed in on this device or the sign-in has expired, 
      // this asynchronous branch will attempt to sign in the user silently. Cross-device 
      // single sign-on will occur in this branch. 
      showProgressDialog(); 
      opr.setResultCallback(new ResultCallback<GoogleSignInResult>() { 
       @Override 
       public void onResult(GoogleSignInResult googleSignInResult) { 
        hideProgressDialog(); 
        handleSignInResult(googleSignInResult); 
       } 
      }); 
     } 
    } 
3

메서드를 사용하여 로그인 자격 증명이 유효한지 확인할 수 있습니다. 자격 증명의 유효성을 검사하는 데 사용되는 OptionalPendingResult 개체를 반환합니다. 자격 증명이 유효한 경우 OptionalPendingResultisDone() 메서드는 true를 반환합니다. 그런 다음 get 메소드를 사용하여 즉시 결과를 얻을 수 있습니다 (사용 가능한 경우). OptionalPendingResult에 대한

안드로이드 문서 : GoogleSignInApi에 대한 https://developers.google.com/android/reference/com/google/android/gms/common/api/OptionalPendingResult

안드로이드 문서 : 자격 증명이 유효하거나하지 않은 경우 https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInApi

여기에 확인하는 코드입니다.

OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(google_api_client); 
if (opr.isDone()) { 
    // If the user's cached credentials are valid, the 
    // OptionalPendingResult will be "done" and the 
    // GoogleSignInResult will be available instantly. 
    Log.d("TAG", "Got cached sign-in"); 

    GoogleSignInResult result = opr.get(); 

    handleSignInResult(result); 
} 
관련 문제