Firebase Token Authentication error

Chatrapati Shiva picture Chatrapati Shiva · Oct 15, 2016 · Viewed 23k times · Source

I am using firebase storage to upload files , but when I upload I am getting this error

E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.android.gms.internal.zzand: Please sign in before trying to get a token.

I googled it but couldn't get answer for it! I have signed in, in firebase.

Answer

SmartAndroidian picture SmartAndroidian · Jan 3, 2017

I think you didn't sign before uploading files. In onCreate() of launcher activity, try this code

FirebaseAuth mAuth = FirebaseAuth.getInstance(); 

Then in onStart(),

FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
  // do your stuff
} else {
  signInAnonymously();
}

signInAnonymously()

private void signInAnonymously() {
    mAuth.signInAnonymously().addOnSuccessListener(this, new  OnSuccessListener<AuthResult>() {
            @Override
            public void onSuccess(AuthResult authResult) {
                // do your stuff
            }
        })
        .addOnFailureListener(this, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                Log.e(TAG, "signInAnonymously:FAILURE", exception);
            }
        });
}

This may solve your problem