我正在尝试为Android编写一个应用程序,通过电子邮件/密码使用Firebase身份验证。它已启用。然而,教程和Github中的示例代码显示:
私有FirebaseAuth真相;
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 ”不存在一样。然而,最新的文件说不然。
非常感谢任何帮助。
答案 0 :(得分:2)
将com.google.firebase:firebase-core:9.0.2'
依赖项替换为com.google.firebase:firebase-auth:9.0.2
依赖项。所以:
compile 'com.google.firebase:firebase-auth:9.0.2'
而不是
您的依赖项下的 compile 'com.google.firebase:firebase-core:9.0.2'
。
我没有在核心依赖项中找到FirebaseAuth类,但我确实在 auth 依赖项中找到了它。此外,如果您签出their依赖项列表,它们不会添加核心依赖项,则会添加 auth 依赖项。
答案 1 :(得分:0)
根据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
希望它有所帮助。