尝试写入Cloud Firestore时出现IllegalArgumentException

时间:2017-10-27 01:35:06

标签: android firebase google-cloud-firestore

我正在使用Firebase并创建我的注册流程。

对于常规电子邮件/密码身份验证,我可以成功写入Cloud Firestore。我已经在实际数据库中查看了我的数据,所以我知道它已成功写入:

           @Override
        public void onComplete(@NonNull Task<Void> task) {
            Log.v("INPUT_TEXT", user.getDisplayName());
            Toast.makeText(getApplicationContext(), user.getDisplayName().toString(), Toast.LENGTH_LONG).show();
            Map<String, Object> userMap = new HashMap<>();
            userMap.put("Display_Name", user.getDisplayName());
            userMap.put("ID", user.getUid());
            userMap.put("Provider", user.getProviders());
            mStoreBaseRef.collection("Users").add(userMap);
        }
    });

但是,使用Facebook身份验证:

private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
                    FirebaseAuth loggedInAuth = FirebaseAuth.getInstance();
                    String ID = loggedInAuth.getCurrentUser().getUid();
                    String displayName = mAuth.getCurrentUser().getDisplayName();
                    HashMap<String, Object> id = new HashMap<>();
                    id.put("user_id", ID);
                    id.put("display_name", displayName);
                    id.put("provider", mAuth.getCurrentUser().getProviderData());
                    mStoreBaseRef.collection("Users").add(id);

                    // 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(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(getApplicationContext(), "Authentication failed.",
                                Toast.LENGTH_SHORT).show();

                    } else {
                        Toast.makeText(getApplicationContext(), "Authentication_Success", Toast.LENGTH_LONG).show();
                    }

                }
            });

我收到以下错误:

java.lang.IllegalArgumentException: Invalid data. Unsupported type: com.google.android.gms.internal.zzdnb
                                                                           at com.google.firebase.firestore.zzl.zzqe(Unknown Source)
                                                                           at com.google.firebase.firestore.zzk.zza(Unknown Source)
                                                                           at com.google.firebase.firestore.zzk.zza(Unknown Source)
                                                                           at com.google.firebase.firestore.zzk.zza(Unknown Source)
                                                                           at com.google.firebase.firestore.zzk.zza(Unknown Source)
                                                                           at com.google.firebase.firestore.zzk.zza(Unknown Source)
                                                                           at com.google.firebase.firestore.DocumentReference.set(Unknown Source)
                                                                           at com.google.firebase.firestore.DocumentReference.set(Unknown Source)
                                                                           at com.google.firebase.firestore.CollectionReference.add(Unknown Source)
                                                                           at com.troychuinard.fanpolls.SignupActivity$2.onComplete(SignupActivity.java:180)
                                                                           at com.google.android.gms.tasks.zzf.run(Unknown Source)
                                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:148)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5527)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

1 个答案:

答案 0 :(得分:0)

如果我们无法将您提供给我们的类型自动转换为我们支持的类型(类似于custom objects),就会发生此错误。检查您放入userMap的类型,如有必要,请选择更简单的类型。 (有关详细信息,请参阅文档。)