我的应用使用 Firebase 身份验证与 2 个提供商:Facebook 和 Google。为了允许用户使用相同的电子邮件创建 Facebook 和 Google 帐户,我去了 Firebase 控制台并选中了一个选项以允许电子邮件地址使用多个帐户。
现在它可以工作了,但对于 Facebook,电子邮件始终为空。如果用户决定使用 Facebook 登录,我如何获得顶级电子邮件地址(链接到多个帐户)。我不想将提供商链接到一个帐户,我想保持“允许一个邮件地址使用多个帐户”打开。
在这种情况下如何获取邮件地址的任何想法?
[编辑]
Google 和 Facebook api 的初始化:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mAuth = FirebaseAuth.getInstance();
mAuthListener = firebaseAuth ->
{
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null)
{
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
String uuid = user.getUid();
String mail = user.getEmail();
currentUserUid = user.getUid();
//Toast.makeText(LoginActivity.this, "Zalogowano. Email: " + user.getEmail() + " uid: " + user.getUid(),
// Toast.LENGTH_SHORT).show();
if (!logout)
{
List<? extends UserInfo> provider = user.getProviderData();
AuthSocial(user, currentLoginType); //if "allow multiple accounts for mail enabled, user.getEmail always returns null for Facebook, how to get correct top level email for "multi account" here?
}
else
{
//mAuth.signOut();
}
}
else
{
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
};
// [START initialize_fblogin]
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.bt_go_facebook);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>()
{
@Override
public void onSuccess(LoginResult loginResult)
{
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
currentLoginType = "facebook";
}
@Override
public void onCancel()
{
Log.d(TAG, "facebook:onCancel");
// [START_EXCLUDE]
//updateUI(null);
// [END_EXCLUDE]
}
@Override
public void onError(FacebookException error)
{
Log.d(TAG, "facebook:onError", error);
// [START_EXCLUDE]
//updateUI(null);
// [END_EXCLUDE]
}
});
// [END initialize_fblogin]