簡體   English   中英

Android firebase 在嘗試訪問存儲時拋出身份驗證錯誤

[英]Android firebase throws authentication error while trying to access storage

編輯:在清理項目並使緩存無效后,我剛剛重新啟動了 Android Studio。 現在我收到這個錯誤 -

E/StorageException: {  "error": {    "code": 403,    "message": 
"Permission denied. Could not perform this operation"  }}

我收到以下無限打印的錯誤。

2020-09-27 17:00:32.931 11755-11863/com.example.XXXXXX E/StorageUtil:獲取令牌時出錯 java.util.concurrent.ExecutionException:com.google.firebase.internal.api.FirebaseNoSignedInUserException:請先登錄試圖獲得令牌。

在我的應用程序中,我已經正確創建了用戶,並且FirebaseAuth.getInstance().getCurrentUser(); 不返回空值。 但如果是這樣,我會通過成功登錄或創建另一個用戶來處理它。 我的應用程序現在在不到半天的時間內創建了 160 多個用戶。 我認為我什至沒有多次運行該應用程序進行測試。 在身份驗證設置中啟用了“使用電子郵件登錄”和“匿名登錄”選項。

當我嘗試訪問存儲時,問題就開始了。 我收到上述身份驗證令牌錯誤。 文件夾和文件存在,這就是我嘗試下載文件的方式 -

            fstore.child("gs://XXXXXX-XXXX.appspot.com/Books/XXXX").listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
            @Override
            public void onSuccess(ListResult listResult) {
                for(StorageReference sref : listResult.getItems())
                {
                    tempFilename = sref.getName();
                    File tmpFile = new File(tempSubDir, tempFilename);
                    try {
                        tmpFile.createNewFile();
                        sref.getFile(tmpFile).addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                Toast.makeText(tabtwoactivity.this, "File download failed!", Toast.LENGTH_LONG).show();
                                System.out.println("ERROR: "+ e.toString());
                            }
                        });
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    //System.out.println("IIIIII: "+sref.getName());
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(tabtwoactivity.this, "Fetching Directory XXXXX Failed", Toast.LENGTH_LONG).show();
            }
        });

我試過使用fstore.child("XXXX").listAll()但這給了我fstore.child("XXXX").listAll()不同的錯誤,主要集中在Folder not found 我的存儲有文件夾和文件。 我什至玩過存儲規則—— allow read, write; allow read, write: if request.auth!=nullallow read, write: if request.auth==null 但沒有任何效果。

我究竟做錯了什么?

將其粘貼到您的 google.json 中:

service firebase.storage {
  // The {bucket} wildcard indicates we match files in all storage buckets
  match /b/{bucket}/o {
    // Match filename
    match /filename {
      allow read: if true;
      allow write: if true;
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM