您好我想在我的应用程序选项中添加登录和注册帐户。我使用firebase auth。 我的Graddle看起来像这样
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.micha.shoppinglist"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.google.firebase:firebase-storage:11.8.0'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
// butter knife
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
testCompile 'junit:junit:4.12'
// room
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
// stetho
compile 'com.facebook.stetho:stetho:1.3.1'
// For OkHttp3
dependencies {
compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'
}
// For OkHttp
dependencies {
compile 'com.facebook.stetho:stetho-okhttp:1.3.1'
}
// For UrlConnection
dependencies {
compile 'com.facebook.stetho:stetho-urlconnection:1.3.1'
}
}
apply plugin: 'com.google.gms.google-services'
我注册帐户的功能看起来像这样
mAuth = FirebaseAuth.getInstance();
mAuth.createUserWithEmailAndPassword("myemail@op.pl", "P@ssw0rd")
.addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Toast.makeText(context, "Authentication passed.",
Toast.LENGTH_SHORT).show();
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
Log.d("Error", task.getException().getMessage());
Toast.makeText(context, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
我在firebase控制台选项中启用登录/注册电子邮件/密码,我收到此错误
03-31 23:48:46.481 26065-26065 / com.example.micha.shoppinglist D /错误:发生了内部错误。 [未配置访问权限。之前或已禁用Google Identity Toolkit API尚未在项目781137572465中使用。访问https://console.developers.google.com/apis/api/identitytoolkit.googleapis.com/overview?project=781137572465启用它,然后重试。如果您最近启用了此API,请等待几分钟,以便将操作传播到我们的系统并重试。 ]
我不知道为什么,因为我不想使用谷歌登录表单。 如果有人能帮助我,我将不胜感激。 :)