Google Firebase身份验证示例不起作用

时间:2016-07-04 22:20:49

标签: android firebase firebase-authentication

我正在尝试编写Firebase用户创建的简单测试。我只是从文档中复制了代码,然后更改了网址,但它不起作用。

public class MainActivity extends AppCompatActivity {
    public static final String FIREBASE_URL = "https://<firebase-application-name>.firebaseio.com/";

    Firebase ref;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Firebase.setAndroidContext(this);
        ref = new Firebase(FIREBASE_URL);
    }

    public void signup(View view) {
        ref.createUser("bobtony@firebase.com", "correcthorsebatterystaple", new Firebase.ValueResultHandler<Map<String, Object>>() {
            @Override
            public void onSuccess(Map<String, Object> result) {
                System.out.println("Successfully created user account with uid: " + result.get("uid"));
            }

            @Override
            public void onError(FirebaseError firebaseError) {
                System.out.println("error");
            }
        });
    }
}

1 个答案:

答案 0 :(得分:0)

  

在从Firebase服务器检索和保存数据之前,您需要设置身份验证并添加限制数据访问的规则,并在保存之前验证用户输入。

请更改Firebase项目的规则

{

 "rules": {

".read": "auth == null",

".write": "auth == null"

  }

}

或尝试以下代码

  {

  "rules": {

      ".read": true,

      ".write": true

  }

}