如何在Firebase中获得与当前用户的关联帐户 [英] How to get linked account with current user in firebase
本文介绍了如何在Firebase中获得与当前用户的关联帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的Firebase帐户链接到我的Google帐户和Facebook帐户,直到这里一切正常为止.这是我如何链接帐户的代码.
I am trying to link my firebase account to my google account and facebook account, and till here everything is working fine.here is my code how I am linking accounts.
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();
}
}
});
现在,我想获取,是我当前的帐户已链接到facebook还是google.是否可以获取此信息,还是应该将这些信息保存到数据库中?
推荐答案
现在我想获得我的当前帐户是否已链接到facebook或google?
Now I want to get, is my current account is linked to facebook or google?
您可以检查提供商ID,以查看用户是否已通过Google或Facebook登录,如下所示:
You can check the provider id to see if the user is signed in with Google or Facebook like this:
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser != null) {
for (UserInfo userInfo : firebaseUser.getProviderData()) {
if (userInfo.getProviderId().equals("google.com")) {
Log.d(TAG, "User is signed in with Google");
} else if(userInfo.getProviderId().equals("facebook.com")) {
Log.d(TAG, "User is signed in with Facebook");
}
}
}
您还可以使用以下代码:
You can also use the following code:
List<? extends UserInfo> infos = user.getProviderData();
for (UserInfo ui : infos) {
if (ui.getProviderId().equals(GoogleAuthProvider.PROVIDER_ID)) {
Log.d(TAG, ui.getProviderId());
}
}
这篇关于如何在Firebase中获得与当前用户的关联帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文