【发布时间】: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