【问题标题】:Couldn't able to retrieve google provider's user email address from Firebase无法从 Firebase 检索 Google 提供商的用户电子邮件地址
【发布时间】:2017-03-08 00:02:55
【问题描述】:

我按照 Firebase 文档在文档的管理用户部分检索到用户的提供商特定的个人资料信息。

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
for (UserInfo profile : user.getProviderData()) {
    // Id of the provider (ex: google.com)
    String providerId = profile.getProviderId();

    // UID specific to the provider
    String uid = profile.getUid();

    // Name, email address, and profile photo Url
    String name = profile.getDisplayName();
    String email = profile.getEmail();
    Uri photoUrl = profile.getPhotoUrl();
};

我可以获取提供商 id、uid、DisplayName 但我无法获取电子邮件。

下面是GoogleSignInOptions 代码和GoogleApiClient,可以访问 Google 登录 API 代码

    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.gmaptest_web_client_id))
            .requestEmail()
            .requestScopes(new Scope(Scopes.EMAIL))
            .build();

    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addScope(new Scope(Scopes.EMAIL))
            .build();

【问题讨论】:

    标签: android firebase firebase-authentication googlesigninapi


    【解决方案1】:

    转到您的项目控制台 -> 身份验证 -> 登录方法 -> 每个电子邮件地址一个帐户(防止使用相同的电子邮件地址创建多个帐户)。 删除已创建的帐号,重新登录,即可获取邮箱地址。

    //我只是想知道你为什么使用'user.getProviderData()',user.getEmail()就足够了。

    【讨论】:

    • 根据 Firebase 文档获取用户的特定于提供商的个人资料信息,我使用了 getProviderData 方法,无论 user.getEmail() 是如何工作的。
    猜你喜欢
    • 2015-03-01
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多