2

Arbeits ich diesen Code habenGoogle Log-in nicht mit Firebase

public class SignInActivity extends BaseActivity implements 
     GoogleApiClient.OnConnectionFailedListener{ 

    private static final String TAG = "SIA"; 
    private static final String USER_ID = "USER_SI_SUCCESS"; 
    private FirebaseAuth mAuth; 
    private GoogleApiClient mGoogleApiClient; 


    private static final int RC_SIGN_IN = 103; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_sign_in); 

     // Initialize authentication and set up callbacks 
     mAuth = FirebaseAuth.getInstance(); 

     // GoogleApiClient with Sign In 
     mGoogleApiClient = new GoogleApiClient.Builder(this) 
       .enableAutoManage(this, this) 
       .addApi(Auth.GOOGLE_SIGN_IN_API, 
         new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
           .requestEmail() 
           .requestIdToken(getString(R.string.default_web_client_id)) 
           .build()) 
       .build(); 
    } 

    public void processSignIn(View view){ 
     Intent intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
     startActivityForResult(intent, RC_SIGN_IN); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);   
     if (requestCode == RC_SIGN_IN) { 
      GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
      handleGoogleSignInResult(result); 
     } 
    } 

    private void handleGoogleSignInResult(GoogleSignInResult result) { 
     Log.e(TAG, "handleSignInResult:" + result.getStatus()); 
     if (result.isSuccess()) { 
      // Successful Google sign in, authenticate with Firebase. 
      GoogleSignInAccount acct = result.getSignInAccount(); 
      firebaseAuthWithGoogle(acct); 
     } else { 
      // Unsuccessful Google Sign In, show signed-out UI 
      Log.e(TAG, "Google Sign-In failed."); 
     } 
    } 

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 
     AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 
     showProgressDialog(getString(R.string.profile_progress_message)); 
     mAuth.signInWithCredential(credential) 
       .addOnSuccessListener(this, new OnSuccessListener<AuthResult>() { 
        @Override 
        public void onSuccess(AuthResult result) { 
         handleFirebaseAuthResult(result); 
        } 
       }) 
       .addOnFailureListener(this, new OnFailureListener() { 
        @Override 
        public void onFailure(@NonNull Exception e) {      
         handleFirebaseAuthResult(null); 
        } 
       }); 
    } 

    public String getUid() { 
     return FirebaseAuth.getInstance().getCurrentUser().getUid(); 
    } 

    private void handleFirebaseAuthResult(AuthResult result) { 
     // TODO: This auth callback isn't being called after orientation change. Investigate. 
     dismissProgressDialog(); 
     if (result != null) { 
      Log.e(TAG, "handleFirebaseAuthResult:USER_ID"); 
      Intent porstSIIntent = new Intent(SignInActivity.this, MainActivity.class); 

      porstSIIntent.putExtra(USER_ID, result.getUser().getUid());   
      SignInActivity.this.startActivity(porstSIIntent); 

     } else { 
      Toast.makeText(this, "Authentication failed.", Toast.LENGTH_SHORT).show(); 
      return; 
     } 
    } 

    @Override 
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 
     Log.e(TAG, "onConnectionFailed:" + connectionResult); 
    } 
} 

mit

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:24.2.0' 
    compile 'com.android.support:design:24.2.0' 
    compile 'com.android.support:recyclerview-v7:24.2.0' 
    compile 'com.android.support:cardview-v7:24.2.0' 
    //Firebase depedencies 
    compile 'com.firebaseui:firebase-ui-database:0.4.0' 
    compile 'com.google.firebase:firebase-auth:9.2.1' 
    compile 'com.google.firebase:firebase-common:9.0.2' 
    //compile 'com.google.android.gms:play-services-auth:9.2.1' 
    compile 'com.google.firebase:firebase-storage:9.2.1' 
    compile 'com.google.firebase:firebase-database:9.2.1' 
    compile 'com.google.android.gms:play-services-auth:9.2.1' 
    compile 'com.google.android.gms:play-services-location:9.2.1' 
    ///compile 'com.onesignal:OneSignal:[email protected]' 
    // Required for OneSignal, even if you have added FCM. 
    compile 'com.google.android.gms:play-services-gcm:9.2.1' 
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3' 
    compile 'com.github.bumptech.glide:glide:3.6.0' 
    compile 'de.hdodenhof:circleimageview:2.0.0' 
    compile 'com.mikhaellopez:hfrecyclerview:1.0.0' 
    compile 'com.daimajia.numberprogressbar:library:[email protected]' 
    compile 'com.atlassian.commonmark:commonmark:0.6.0' 
    compile 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.6.0' 
    compile 'com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:0.6.0' 
    compile 'ren.qinc.edit:lib:0.0.3' 
    compile project(':drawer') 

    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3' 
    compile 'com.miguelcatalan:materialsearchview:1.4.0' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'com.flaviofaria:kenburnsview:1.0.5' 
    compile 'com.jpardogo.materialtabstrip:library:1.1.1' 
} 

die Google-Anmeldung ist nicht funktioniert und ich erhalte die folgende Log

E/SIA: handleSignInResult:Status{statusCode=unknown status code: 12501, resolution=null} 
E/SIA: Google Sign-In failed. 

Wichtig: Vor ein paar Monaten funktionierte dieser Code, aber jetzt es wird nicht. Ich weiß nicht warum. Bitte führen Sie mich.

+1

'Feuerbasis-common: 9.0.2'' << Needs andere Feuerbasis Versionen übereinstimmen (obwohl man auch abnehmen kann; 'common' ist in den anderen enthalten) –

+0

bitte überprüfen Sie dies. Ich hoffe, dies wird Ihnen helfen https://github.com/devfd/react-native-google-signin/issues/22 – Shailesh

+0

Status 12501 zeigt oft an, dass ein Problem mit der in Ihrer Datei google-services.json definierten Konfiguration vorliegt. Überprüfen Sie die Werte für Paketname, SHA1-Schlüssel usw. Versuchen Sie vielleicht, eine neue Datei zu generieren und herunterzuladen. –

Antwort

0

sicherstellen, korrekte Google-service.json und aktiviert Google Login in Authentifizierung haben -> Zeichen in Verfahren in Feuerbasis Konsole

+0

Wie ich sagte, es funktionierte vor ein paar Monaten, habe ich alle Konfigurations-Sachen in Firebase-Konsole und eine richtige google-service.json gibt es in meiner App –

0

Hier ist die aktualisierte Tutorial Google für die Implementierung signin Feuerbasis in android Google Singin using firebase in android

mit

Tutorial enthält

  • Ihre Anwendung registrieren mit Feuerbasis

  • Einrichtung gradle Dateien

  • Integrieren Sie Ihre Anwendung mit Google signin Code