Firebase权限被拒绝错误 [英] Firebase Permission denied Error

查看:237
本文介绍了Firebase权限被拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是每次都会显示相同的错误。

  W / SyncTree:在/ child失败时收听:FirebaseError:Permission denied 

我的firebase规则

  {
Condition:sunny,
child:5
}

我的AndroidManifest.xml

 <?xml version =1.0encoding =utf-8?> 
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.mohit.firebase>

<使用权限android:name =android.permission.INTERNET/>

应用程序$ b $ android:allowBackup =true
android:icon =@ mipmap / ic_launcher
android:label =@ string / app_name
android:supportsRtl =true
android:theme =@ style / AppTheme
>
< activity android:name =。MainActivity>
< intent-filter>

< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< / application>

< / manifest>

我的mainactivity.java
包com.mohit.firebase;

  import android.support.v7.app.AppCompatActivity; 
导入android.os.Bundle;
导入android.util.Log;
导入android.view.View;
导入android.widget.Button;
导入android.widget.TextView;

导入com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;

公共类MainActivity扩展AppCompatActivity {

TextView tv;
按钮bt1;
按钮bt2;
Firebase mRootRef;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv =(TextView)findViewById(R.id.button);
bt1 =(Button)findViewById(R.id.button);
bt2 =(Button)findViewById(R.id.button2);
Firebase.setAndroidContext(this);
mRootRef =新的Firebase(https://superb-flag-126719.firebaseio.com/);
Log.d(fb,Firebase Object:+ String.valueOf(mRootRef));


$ b @Override
protected void onStart(){
super.onStart();

Firebase mchild = mRootRef.child(child);
mchild.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
String condition =(String)dataSnapshot.getValue();
Log.d(fb,String get:+ condition);
tv.setText(condition);
}

@Override
public void onCancelled(FirebaseError firebaseError){


});


$ / code $ / pre

我的BuildGraddle

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion23.0.2

defaultConfig {
applicationIdcom.mohit.firebase
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
packagingOptions {
不包括'META-INF / LICENSE'
不包括'META-INF / LICENSE-FIREBASE.txt'
'META-INF / NOTICE '
}
}


依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
testCompile'junit:junit:4.12'
c ompile'c​​om.android.support:appcompat-v7:23.1.1'
compile'c​​om.firebase:firebase-client-android:2.5.2+'
}

我检查了我的firebase网址。这是完全正确的。

解决方案

这是因为您没有授权到数据库,检查实时数据库中的规则选项卡



如果它是

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



这意味着只有经过授权的用户才能写入和读取数据。



更改为

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






允许任何人编写数据库



在进行制作时,请务必使用第一个

I am Very beginner to firebase and trying to get value from my database.

but it showing me same error every time.

    W/SyncTree: Listen at /child failed: FirebaseError: Permission denied

My firebase rules

    {
  "Condition" : "sunny",
  "child" : 5
}

my Androidmanifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mohit.firebase" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

My mainactivity.java package com.mohit.firebase;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;

public class MainActivity extends AppCompatActivity {

    TextView tv;
    Button bt1;
    Button bt2;
    Firebase mRootRef;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv = (TextView) findViewById(R.id.button);
        bt1 = (Button) findViewById(R.id.button);
        bt2 = (Button) findViewById(R.id.button2);
        Firebase.setAndroidContext(this);
        mRootRef = new Firebase("https://superb-flag-126719.firebaseio.com/");
        Log.d("fb","Firebase Object: "  + String.valueOf(mRootRef));

    }

    @Override
    protected void onStart() {
        super.onStart();

        Firebase mchild = mRootRef.child("child");
        mchild.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String condition = (String) dataSnapshot.getValue();
                Log.d("fb","String get: " + condition);
                tv.setText(condition);
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });
    }
}

my BuildGraddle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.mohit.firebase"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.firebase:firebase-client-android:2.5.2+'
}

i checked my firebase url. It's Perfectly Correct.

解决方案

It's because you are not authorized to the Database, check the Rules Tab in the Realtime database

If it's

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

This means only authorized user's can write and read the Data.

Changing to

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

Allows anyone to write the Database

When going for Production be sure to use the first one

这篇关于Firebase权限被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆