0

I'm getting the following error when trying to get the public downloadUrl from FirebaseStorage. I've set my rules to allow full read and write access, and have no problem storing my data in the storage. However, when I try to get the download url, I get this problem. -

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

I've read Firebase getDownloadURL but was still unable to resolve my issue.

Here's my function-

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == 0 && resultCode == RESULT_OK) {

            Uri uri = data.getData();
            final StorageReference filePath = mStorage.child("Photos").child(uri.getLastPathSegment());

            filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

//                    @SuppressWarnings("VisibleForTests") Uri downloadUri = taskSnapshot.getDownloadUrl();
//                    recognizeImage(downloadUri);

                    filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            recognizeImage(uri);
                        }
                    });
                }

            });
        }
    }
Community
  • 1
  • 1
fraiser
  • 929
  • 12
  • 28
  • What do the rules look like? The error says you need to sign in first. – Kato Apr 24 '17 at 21:19
  • I'm still getting the error, but I didn't that it wasn't affecting what I needed to do. So, I'm actually getting the downloadUrl(), even with the error that I get in the Android Monitor, so looks like I don't even need to fix it. – fraiser Apr 24 '17 at 21:36

1 Answers1

1

Please add the following lines of code inside the onCreate method of Activity class

  mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    if (user != null) {

       /* perform your actions here*/


    } else {
        signInAsAnonymous();
    }

 private void signInAnonymously() {
    mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
        @Override
        public void onSuccess(AuthResult authResult) {
                        /* perform your actions here*/

        }
    })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    Log.e("MainActivity", "signFailed****** ", exception);
                }
            });
}

This is not enough to resolve your issue. Now after adding the above code.

Open Firebase Console> Click on AUTHENTICATION from left menu > SIGN-IN METHOD > ENABLE ANONYMOUS Now build and run the app if not works let me know

Suresh Maidaragi
  • 2,173
  • 18
  • 25