Java 面临与Firebase Cloud Firestore相关的问题
我试图将数据存储到Firebase Cloud Firestore,但在运行我的应用程序后,它在日志中显示了此错误 [Firestore]:在Backpaper注册时写入失败/WSjZoirLf8WRBuGCVbUZ:状态{code=PERMISSION\u DENIED,description=Missing或permissions.,cause=null} 这是我代码的一部分Java 面临与Firebase Cloud Firestore相关的问题,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我试图将数据存储到Firebase Cloud Firestore,但在运行我的应用程序后,它在日志中显示了此错误 [Firestore]:在Backpaper注册时写入失败/WSjZoirLf8WRBuGCVbUZ:状态{code=PERMISSION\u DENIED,description=Missing或permissions.,cause=null} 这是我代码的一部分 fb=FirebaseFirestore.getInstance(); map=new HashMap<St
fb=FirebaseFirestore.getInstance();
map=new HashMap<String>();
map.put("Name of Department",txtDepartment);
map.put("Name of Student",txtStudentName);
map.put("Registration No",txtRegNo);
map.put("CGPA in Previous Semester",txtCgpa);
map.put("Phone",txtPhoneNo);
map.put("Email",txtEMail);
map.put("Subject 1",txtSubject1);
map.put("Subject 2",txtSubject2);
map.put("Subject 3",txtSubject3);
map.put("Subject 4",txtSubject4);
map.put("Subject 5",txtSubject5);
map.put("Payment Details(Rs.)",txtPaymentDetails);
map.put("Payment Date",txtPaymentDate);
fb.collection("Backpaper Registration").add(map).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull Task<DocumentReference> task) {
if(task.isSuccessful()){
Toast.makeText(Backpaper.this, "Registration Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Backpaper.this,Academic.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP));
finish();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Backpaper.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
fb=FirebaseFirestore.getInstance();
map=新的HashMap();
地图放置(“部门名称”,TXT部门);
map.put(“学生姓名”,txtStudentName);
地图放置(“注册号”,txtRegNo);
map.put(“上学期CGPA”,txtCgpa);
地图放置(“电话”,txtPhoneNo);
map.put(“电子邮件”,txtEMail);
地图放置(“主题1”,txtSubject1);
地图放置(“主题2”,txtSubject2);
地图放置(“主题3”,txtSubject3);
地图放置(“主题4”,txtSubject4);
地图放置(“主题5”,txtSubject5);
map.put(“付款明细”,txtPaymentDetails);
map.put(“付款日期”,txtPaymentDate);
fb.collection(“Backpaper Registration”).add(map.addOnCompleteListener(新的OnCompleteListener)(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
Toast.makeText(Backpaper.this,“注册成功”,Toast.LENGTH_SHORT.show();
startActivity(新意图(背景文件、本课程、学术课程)、addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP));
完成();
}
}
}).addOnFailureListener(新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e){
Toast.makeText(Backpaper.this,e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
有人能帮我吗?你应该看看Firebase上的规则 更改允许
读、写:如果为false;真实代码>
否:
不建议选择此解决方案,因为它会导致
数据库不安全
仅用于测试目的。您需要在Firebase控制台上设置Firebase规则
如果您已登录project,则规则设置可能如下所示:
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
如果只是演示该函数,则调用设置规则:
// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
你可以在这里找到更正式的文件
这可能是因为您没有向firebase授予读写权限。
将Firebase数据库更改为测试模式。
1.转到firebase数据库控制台
2.转到规则
3.在测试模式下启动
这将更改允许读、写:true
这将关闭数据库安全性,但出于测试目的,建议您将Firebase数据库切换到测试模式了吗?