繁体   English   中英

Firebase身份验证API电子邮件/密码Android

[英]Firebase Authentication API Email/Password Android

我正在尝试编写一个通过电子邮件/密码使用Firebase身份验证的android应用程序。 已启用。 但是,本教程以及示例中的代码在Github中显示:

私有FirebaseAuth mAuth;

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-core:9.0.2'



}


apply plugin: 'com.google.gms.google-services'

但是,我收到一个错误,好像“ FirebaseAuth ”不存在。 但是,最新文档另有说明。

Github示例代码

在此处输入图片说明

任何帮助将不胜感激。

com.google.firebase:firebase-auth:9.0.2依赖性替换com.google.firebase:firebase-core:9.0.2'依赖性。 所以:

compile 'com.google.firebase:firebase-auth:9.0.2'

代替

在您的依赖项下compile 'com.google.firebase:firebase-core:9.0.2'

我没有在核心依赖项中找到FirebaseAuth类,但在身份验证依赖项中找到了它。 此外,如果您签出他们的依赖项列表,则他们不添加核心依赖项,而是添加auth依赖项。

根据firebase网页上的文档,您应该使用firebase中的URL创建一个Firebase对象,然后从那里创建带有密码的用户名或登录。您显示的代码为此使用了FirebaseAuth。

这是创建新用户的代码:

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
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) {
        // there was an error
    }
});

这是登录他的代码:

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithPassword("bobtony@firebase.com", "correcthorsebatterystaple", new Firebase.AuthResultHandler() {
    @Override
    public void onAuthenticated(AuthData authData) {
        System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
    }
    @Override
    public void onAuthenticationError(FirebaseError firebaseError) {
        // there was an error
    }
});

从此处的快速入门指南中获得所有这些信息: https : //www.firebase.com/docs/android/guide/login/password.html#section-logging-in

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM