简体   繁体   中英

Why I can't get data from Firebase Storage?

I need to get data from Firebase Storage and Firestore Database. I get text data from Firestore Database (links of images and songs in Firebase Storage), but I can't retrieve song and stream it in my app. I get an error form logcat:

E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.

But I don't sign in users in my app.

logcat also writes an error:

E/StorageException: {  "error": {    "code": 404,    "message": "Not Found."  }}
    java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found."  }}

logcat:

2022-02-17 06:03:27.264 14195-14268/com.example.clearmind1 E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
2022-02-17 06:03:27.265 14195-14268/com.example.clearmind1 W/NetworkRequest: no auth token for request
2022-02-17 06:03:27.265 14195-14268/com.example.clearmind1 W/NetworkRequest: No App Check token for request.
2022-02-17 06:03:27.272 14195-14270/com.example.clearmind1 E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
2022-02-17 06:03:27.273 14195-14270/com.example.clearmind1 W/NetworkRequest: no auth token for request
2022-02-17 06:03:27.273 14195-14270/com.example.clearmind1 W/NetworkRequest: No App Check token for request.
2022-02-17 06:03:27.277 14195-14276/com.example.clearmind1 E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
2022-02-17 06:03:27.277 14195-14276/com.example.clearmind1 W/NetworkRequest: no auth token for request
2022-02-17 06:03:27.277 14195-14276/com.example.clearmind1 W/NetworkRequest: No App Check token for request.
2022-02-17 06:03:27.799 14195-14270/com.example.clearmind1 E/StorageException: StorageException has occurred.
    Object does not exist at location.
     Code: -13010 HttpResult: 404
2022-02-17 06:03:27.799 14195-14276/com.example.clearmind1 E/StorageException: StorageException has occurred.
    Object does not exist at location.
     Code: -13010 HttpResult: 404
2022-02-17 06:03:27.801 14195-14276/com.example.clearmind1 E/StorageException: {  "error": {    "code": 404,    "message": "Not Found."  }}
    java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found."  }}
        at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:445)
        at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:462)
        at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:453)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:289)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:76)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:68)
        at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:77)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
2022-02-17 06:03:27.801 14195-14264/com.example.clearmind1 E/StorageException: StorageException has occurred.
    Object does not exist at location.
     Code: -13010 HttpResult: 404
2022-02-17 06:03:27.802 14195-14264/com.example.clearmind1 E/StorageException: {  "error": {    "code": 404,    "message": "Not Found."  }}
    java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found."  }}
        at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:445)
        at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:462)
        at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:453)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:289)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:76)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:68)
        at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:77)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
2022-02-17 06:03:27.809 14195-14270/com.example.clearmind1 E/StorageException: {  "error": {    "code": 404,    "message": "Not Found."  }}
    java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found."  }}
        at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:445)
        at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:462)
        at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:453)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:289)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:76)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:68)
        at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:77)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
2022-02-17 06:03:27.955 14195-14268/com.example.clearmind1 E/StorageException: StorageException has occurred.
    Object does not exist at location.
     Code: -13010 HttpResult: 404
2022-02-17 06:03:27.955 14195-14268/com.example.clearmind1 E/StorageException: {  "error": {    "code": 404,    "message": "Not Found."  }}
    java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found."  }}
        at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:445)
        at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:462)
        at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:453)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:289)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:76)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:68)
        at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:77)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)

Here I get text data from server:

ArrayList childItemList = new ArrayList<>();
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection(category).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
    @Override
    public void onComplete(@NonNull Task<QuerySnapshot> task) {
        if (task.isSuccessful()) {
            progressDialog.dismiss();
            for (QueryDocumentSnapshot document : task.getResult()) {
                Log.d(TAG, document.getId() + " => " + document.getData());
                ChildItem childItem = new ChildItem();
                childItem.setTrackTitle(document.getString("title"));
                childItem.setAuthor(document.getString("author"));
                childItem.setDuration(document.getString("duration"));
                childItem.setImage(document.getString("image"));
                childItem.setTrack(document.getString("track"));
                childItemList.add(childItem);
            }
        } else {
            Log.w(TAG, "Error getting documents.", task.getException());
            Toast.makeText(BrowseTracksActivity.this, task.getException() + "", Toast.LENGTH_SHORT);
        }
        childItemList.add(getDefaultChildItem());
        setAdapter();
    }
});

Here I'm trying to stream song (I'm sending link of the song through intent to another activity):

Intent intent=getIntent();
music= new MediaPlayer();
music.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
    String s=intent.getStringExtra("track");
    music.setDataSource(intent.getStringExtra("track"));
    music.prepare();
    music.start();

    Toast.makeText(this, "Audio started playing..", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
    // this line of code is use to handle error while playing our audio file.
    Toast.makeText(this, "Error found is " + e, Toast.LENGTH_SHORT).show();
}

the error tells you that you need to sign in your users first. If you don't want to sign in your users, but want them to access the database, You can give them a token by signing them in anonymously. This way, you don't have to collect authentication data eg email, password, social login etc.

You can log in your user in the main activity without interrupting the flow.

Here is the code

mAuth.signInAnonymously()
    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                // Sign in success, User can now write and read the database.
                Log.d(TAG, "signInAnonymously:success");
                FirebaseUser user = mAuth.getCurrentUser();
                updateUI(user);
            } else {
                // If sign in fails, display a message to the user.
                Log.w(TAG, "signInAnonymously:failure", task.getException());
                Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
                        Toast.LENGTH_SHORT).show();
                updateUI(null);
            }
        }
    });

Initialize FirebaseAuth in the onCreate method.

Here is the firebase documentation Firebase anonymous log in Android

Don't forget to change your database rules

"rules": {
".read": "auth != null",
".write": "auth != null"

} }

OR...

You can allow all users to read and write your database (Not recommended), by just changing your rules to

"rules": {
".read": "auth == null",
".write": "auth == null"}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM