Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Token Authentication error

Tags:

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.

like image 480
Chatrapati Shiva Avatar asked Oct 15 '16 10:10

Chatrapati Shiva


People also ask

How do I refresh my firebase token?

You can refresh a Firebase ID token by issuing an HTTP POST request to the securetoken.googleapis.com endpoint. The refresh token's grant type, always "refresh_token". A Firebase Auth refresh token. The number of seconds in which the ID token expires.


1 Answers

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

Note: Initially enable anonymous sign-in in your firebase project. Authentication -> Sign-in method

like image 151
SmartAndroidian Avatar answered Oct 26 '22 06:10

SmartAndroidian