【问题标题】:Firebase facebook and gmail accounts are not mergedFirebase facebook 和 gmail 帐户未合并
【发布时间】:2021-03-20 18:13:47
【问题描述】:

当我使用 gmail 和 facebook 登录我的 android 应用程序时,会在 firebase 上创建两个单独的身份验证凭据。可以合并吗?

【问题讨论】:

    标签: java android firebase firebase-authentication


    【解决方案1】:
    1. 使用任何身份验证提供程序或方法登录用户。 (假设您的用户已经使用 Google 登录)。

    2. 获取新身份验证提供程序 (Facebook) 的凭据。

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());

    1. AuthCredential 对象传递给登录用户的“linkWithCredential”方法。
    mAuth.getCurrentUser().linkWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "linkWithCredential:success");
                        FirebaseUser user = task.getResult().getUser();
                        updateUI(user);
                    } else {
                        Log.w(TAG, "linkWithCredential:failure", task.getException());
                        Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        updateUI(null);
                    }
                }
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2020-02-01
      • 2018-03-21
      • 1970-01-01
      • 2016-01-21
      • 1970-01-01
      • 2022-01-09
      相关资源
      最近更新 更多