简体   繁体   English

Firebase 实时数据库:DatabaseError 权限被拒绝

[英]Firebase Realtime Database: DatabaseError Permission denied

I'm calling data from a Firebase Realtime Database into Android, and I get the following error: "W/SyncTree: Listen at /Datas failed: DatabaseError: Permission denied"我正在将 Firebase 实时数据库中的数据调用到 Android 中,但出现以下错误:“W/SyncTree: Listen at /Datas failed: DatabaseError: Permission denied”

My rules are set to:我的规则设置为:

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

Changing "auth == null" to true also throws the same permission error.将“auth == null”更改为 true 也会引发相同的权限错误。

I do not want to give user permission to write the db, just read.我不想给用户写数据库的权限,只是读取。

I have already:我已经:
Connected the app to Firebase将应用连接到 Firebase
Set dependencies设置依赖项
Written to the database写入数据库

Any ideas?有任何想法吗?
Thanks谢谢

Change the rules to :将规则更改为:

{
  "rules": {
    ".read": true,
    ".write": false
  }
}

The google-services.json file needed to be downloaded and added to the app root directory.需要下载 google-services.json 文件并将其添加到应用程序根目录。 The error "DatabaseError: Permission denied" no longer appears.不再出现错误“数据库错误:权限被拒绝”。

Fist try with change rules of read / write permission if it's still not working then try to clean and rebuild project.如果仍然无法正常工作,请先尝试更改读/写权限规则,然后尝试清理并重建项目。 In my case i added another project google-service.json due to project change and this error prompt whenever try to write something in database then i search previous DB url in project and that URL had in auto generated files then I clean and rebuild project and it's working fine now .在我的情况下,由于项目更改,我添加了另一个项目 google-service.json 并且每当尝试在数据库中写入内容时都会出现此错误提示,然后我在项目中搜索以前的数据库 url 并且该 URL 包含在自动生成的文件中,然后我清理并重建项目和现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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