2016-05-27 14 views
17

मैं फ़ायरबेस के लिए बहुत शुरुआत कर रहा हूं और अपने डेटाबेस से मूल्य प्राप्त करने की कोशिश कर रहा हूं।फायरबेस अनुमति अस्वीकार त्रुटि

लेकिन यह मुझे हर बार एक ही त्रुटि दिखा रहा है।

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

मेरे firebase नियम

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

मेरी 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> 

मेरे mainactivity.java पैकेज 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) { 

      } 
     }); 
    } 
} 

मेरी 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+' 
} 

मैं अपने firebase यूआरएल की जाँच की। यह पूरी तरह से सही है।

+0

आप अपने डेटाबेस संरचना का एक नमूना पोस्ट कर सकते हैं? साथ ही, क्या आप मौके से सुरक्षा नियमों को लागू कर रहे हैं? –

+0

वर्तमान में फायरबेस में डिफ़ॉल्ट नियम केवल अधिकृत उपयोगों के लिए पढ़ने और लिखने के संचालन की अनुमति देता है। –

उत्तर

72

यह है क्योंकि आप डाटाबेस लिए अधिकृत नहीं हैं, रीयलटाइम डेटाबेस में नियम टैब की जाँच

यदि यह है

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

इसका मतलब यह है केवल अधिकृत उपयोगकर्ता के बारे में और डेटा पढ़ सकते हैं।

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

को बदलने किसी डाटाबेस

लिखने देता है जब उत्पादन के लिए जा रहा का उपयोग सुनिश्चित करें पहले एक

+3

हो सकता है कि यह सुरक्षा के लिए सबसे अच्छा समाधान न हो। –

+2

हां, लेकिन परीक्षण उद्देश्यों के लिए उपयोग किया जा सकता है –

+0

धन्यवाद। अब यह काम कर रहा है। मैं अधिकृत नहीं था। –

संबंधित मुद्दे