Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用Google认证用户进行Firebase查询_Android_Firebase_Firebase Authentication_Google Signin - Fatal编程技术网

Android 使用Google认证用户进行Firebase查询

Android 使用Google认证用户进行Firebase查询,android,firebase,firebase-authentication,google-signin,Android,Firebase,Firebase Authentication,Google Signin,我已成功地在我的应用程序中实现了Google登录方法功能。用户可以使用其Google帐户登录,但当用户尝试查询Firebase数据库时会出现问题,因为getCurrentUser()方法返回null 我的代码与Firebase文档相同 private void firebaseAuthWithGoogle(String idToken) { AuthCredential credential = GoogleAuthProvider.getCredential(idToken,

我已成功地在我的应用程序中实现了Google登录方法功能。用户可以使用其Google帐户登录,但当用户尝试查询Firebase数据库时会出现问题,因为getCurrentUser()方法返回null

我的代码与Firebase文档相同


private void firebaseAuthWithGoogle(String idToken) {
       AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
       mAuth.signInWithCredential(credential)
               .addOnCompleteListener(getActivity(), 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
                           Log.d(TAG, "signInWithCredential:success");
                           FirebaseUser user = mAuth.getCurrentUser();
                           mainIntent();
                       } else {
                           // If sign in fails, display a message to the user.
                           Log.w(TAG, "signInWithCredential:failure", task.getException());
                       }
                   }
               });
   }



私有void firebaseAuthWithGoogle(字符串idToken){
AuthCredential credential=GoogleAuthProvider.getCredential(idToken,null);
mAuth.SIGNWITH凭证(凭证)
.addOnCompleteListener(getActivity(),new OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
//登录成功,使用登录用户的信息更新UI
Log.d(标记“signInWithCredential:success”);
FirebaseUser=mAuth.getCurrentUser();
maintent();
}否则{
//如果登录失败,则向用户显示消息。
w(标记“signInWithCredential:failure”,task.getException());
}
}
});
}

我如何让Google认证用户作为Firebase用户工作?如果有什么我错过了,请让我知道!谢谢。

mAuth.signInWithCredential(credential)
成功后,您应该能够为该用户查询数据库。如果这对你来说不起作用,那就展示一下。