写权限设置为true

写权限设置为true

本文介绍了Firebase数据库权限被拒绝,读/写权限设置为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我简单的Android应用程序中写入我的Firebase数据库时遇到问题。

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

创建一个简单的类 Message

  import com .google.firebase.database.DatabaseReference; 
import com.google.firebase.database.FirebaseDatabase;

public class Message {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference dbRef = database.getReference();
public String sender;
public String message;

public Message(){}

public Message(String sender,String message){
this.sender = sender;
this.message = message;




$ b

然后设置一个按钮来执行onClick方法 writeNewMessage ,它们是代码的重要代码行:

  int counter = 0; 

public void writeNewMessage(View view){

counter + = 1;
Message messageToWrite = new Message(John,Simple message:+ counter);
String messageId = String.valueOf(counter);

dbRef.child(users)。child(messageId).setValue(messageToWrite);
}

运行时,收到错误:

  W / RepoOperation:setValue at / users / 1失败:DatabaseError:Permission denied 

我知道这个问题似乎很简单,可能已经重复,但我还没有找到任何问题,而没有将他们的错误涉及身份验证或其他组件。这个问题的简单性让我感到困惑。



编辑:我也发现这个错误:

 未能载入模组描述符类: .auth.ModuleDescriptor


解决方案

您的google-services.json问题。



确保应用名称和客户端ID与Firebase控制台中的相同。



如果您不确定从您的项目控制台重新下载google-services.json并将其添加到您的项目中。

I'm having trouble writing to my Firebase database in my simple Android app. I've set my database rules to be public:

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

Created a simple class Message:

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class Message {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference dbRef = database.getReference();
    public String sender;
    public String message;

    public Message(){}

    public Message(String sender, String message) {
        this.sender = sender;
        this.message = message;
    }
}

And set a button to perform the onClick method writeNewMessage with these being the significant lines of code:

int counter = 0;

public void writeNewMessage(View view) {

        counter += 1;
        Message messageToWrite = new Message("John", "Simple message: " + counter);
        String messageId = String.valueOf(counter);

        dbRef.child("users").child(messageId).setValue(messageToWrite);
    }

When running, I receive the error:

W/RepoOperation: setValue at /users/1 failed: DatabaseError: Permission denied

I know this question seems simple and likely to have been repeated, but I have yet to find any that asks this problem without having their error be involved in authentication or some other component. The simplicity of the problem is what confuses me the most.

EDIT: I've also found this error as well:

Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor"
解决方案

This looks like problem with your google-services.json.

Make sure app name and client id are same as in firebase console.

If you are not sure re-download google-services.json from your project's console and add it your project.

这篇关于Firebase数据库权限被拒绝,读/写权限设置为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 23:00