简体   繁体   English

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

[英]Firebase Authentication API Email/Password Android

I am attempting to write an app for android that uses Firebase Authentication via Email/Password. 我正在尝试编写一个通过电子邮件/密码使用Firebase身份验证的android应用程序。 It is enabled. 已启用。 However the tutorial, and the code in Github for the examples are showing: 但是,本教程以及示例中的代码在Github中显示:

private FirebaseAuth mAuth; 私有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'

However, I get an error as if the " FirebaseAuth " doesn't exist. 但是,我收到一个错误,好像“ FirebaseAuth ”不存在。 However the latest documentation says otherwise. 但是,最新文档另有说明。

Github sample code Github示例代码

在此处输入图片说明

Any help would be greatly appreciated. 任何帮助将不胜感激。

Replace the com.google.firebase:firebase-core:9.0.2' dependency with the com.google.firebase:firebase-auth:9.0.2 dependency. com.google.firebase:firebase-auth:9.0.2依赖性替换com.google.firebase:firebase-core:9.0.2'依赖性。 So: 所以:

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

instead of 代替

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

I did not find the FirebaseAuth class in the core dependency but I did find it in the auth dependency. 我没有在核心依赖项中找到FirebaseAuth类,但在身份验证依赖项中找到了它。 Furthermore, if you checkout their dependencies list, they do not add the core dependency, they add the auth dependency instead. 此外,如果您签出他们的依赖项列表,则他们不添加核心依赖项,而是添加auth依赖项。

According to documentation in the firebase web page you should create a Firebase object using the URL from your firebase and from there create usernames with passwords or log them in. The code you showed used this FirebaseAuth for that. 根据firebase网页上的文档,您应该使用firebase中的URL创建一个Firebase对象,然后从那里创建带有密码的用户名或登录。您显示的代码为此使用了FirebaseAuth。

Here is the code to create a new user: 这是创建新用户的代码:

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
    }
});

Here is the code to log him in: 这是登录他的代码:

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
    }
});

Got all of this info from the quick start guide here: https://www.firebase.com/docs/android/guide/login/password.html#section-logging-in 从此处的快速入门指南中获得所有这些信息: https : //www.firebase.com/docs/android/guide/login/password.html#section-logging-in

Hope it helps. 希望能帮助到你。

暂无
暂无

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

相关问题 Android Firebase 电子邮件和密码身份验证不起作用 - Android Firebase Email and password authentication does not work Android-Firebase身份验证不适用于电子邮件/密码设置 - Android - Firebase Authentication not working with Email/Password setup 使用电子邮件和密码进行 Firebase 身份验证 - Firebase Authentication With Email & Password 使用Firebase身份验证通过电子邮件/密码将Firebase连接到Android应用程序 - Connecting Firebase to Android application using Firebase authentication via email/password Firebase 电子邮件和密码身份验证失败 - Firebase email and password authentication fails 自定义登录中的Firebase Android重置密码(不适用于电子邮件身份验证) - Firebase Android reset password in custom Login (not with email authentication) 使用 Android 进行 Firebase 电子邮件和密码身份验证 - 用户注册 - Firebase Email and Password Authentication with android - User sign up Firebase 身份验证与 email 和密码额外字段重复 - Android - ZD52387880E15EA22817A723 - Firebase authentication with email and password extra fields duplicating - Android - Java 如何在Firebase中添加带有电子邮件+密码身份验证的DisplayName? Android的 - How to add DisplayName with email + password authentication in Firebase? Android Android Studio 的 Firebase 工具中缺少 Email 和密码验证 - Missing Email and Password Authentication in Android Studio's Firebase tool
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM