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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With