Firebase Android Auth对象无回调触发 [英] Firebase Android Auth object no callbacks firing

查看:71
本文介绍了Firebase Android Auth对象无回调触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览Firebase文档,以在我的android应用中设置用户身份验证系统.但是由于某种原因,我的FirebaseAuth对象上似乎没有运行任何回调!

I've been going through the Firebase docs to set up a user authentication system in my android app. For some reason however, it doesn't look like any of the callbacks are running on my FirebaseAuth object!

例如按照此处

private void handleFacebookAccessToken(AccessToken token) {
    Log.d("AUTH", "handleFacebookAccessToken:" + token.getToken());
    // ...
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    Log.d("AUTH", "Credential: "+credential);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d("AUTH", "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w("AUTH", "signInWithCredential", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });
}

Facebook的一切都很好,但是当使用检索到的fb凭据登录时,signInWithCredential函数不会运行任何回调,并且在我的用户数据库中似乎什么也没有发生.

Everything fine on the part of Facebook but when it comes to signing in with the retrieved fb credentials, the signInWithCredential function doesn't run any callbacks and nothing seems to happen in my user database.

此外,我尝试了更简单的方法

Furthermore I've tried the much more simpler

mAuth.createUserWithEmailAndPassword(etUserID.getText().toString(), etPassword.getText().toString());

,也没有任何反应.我已经在Firebase控制台中启用了这两个提供程序,并为该项目下载了最新的google-services.json文件.我想念什么吗?

and nothing happens as well. I've enabled both providers in my Firebase console and downloaded the latest google-services.json file for the project. Am I missing something?

刚刚尝试运行快速入门身份验证演示,但效果不佳.我确实在模拟器上看到,除非我更新Google服务,否则该应用程序将无法运行.这是此错误的原因吗?我尝试在各种模拟器上更新google服务,但这只会返回错误.

Just tried running the quick-start authentication demo and it doesn't work as well. I do see on my emulator that this app won't run unless I update google services. Is this the cause of this error? I tried updating google services on various emulators and that just returns an error.

推荐答案

让它只能在真正的android设备上运行,但对模拟器却不走运.

Got it working only on a real android device, but had no lucky with the emulator.

对于设备,您需要在应用gradle文件中添加以下依赖项:

For the device, you'll need to add the following dependency in your app gradle file:

compile 'com.google.android.gms:play-services-auth:9.0.2'

我还没有测试过,但是看来,如果您使用更新的Google Play服务更新模拟器映像,那么它也应该可以工作.

I haven't tested, but it seems that if you update the emulator image with a newer google play services, it also should work.

希望有帮助.

这篇关于Firebase Android Auth对象无回调触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆