【发布时间】:2016-10-24 01:58:20
【问题描述】:
我正在尝试从其 Google Plus 帐户中获取用户的信息,包括性别和年龄。由于这些字段可能是私有的,我认为明确地请求它们可以解决问题。然而,虽然登录对话框明确指出应用程序请求View your complete date of birth,但我却没有得到生日。
这些是我的范围(尝试了许多变体):
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
//.requestScopes(new Scope(Scopes.PROFILE))
//.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestScopes(new Scope("https://www.googleapis.com/auth/user.birthday.read"),
new Scope("https://www.googleapis.com/auth/userinfo.profile"))
//.requestProfile()
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
.build();
在onActivityResult 中使用已弃用的getCurrentPerson 时,我得到空值:
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (mGoogleApiClient.hasConnectedApi(Plus.API)) {
Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (person != null) {
Log.i(TAG, person.getDisplayName()); //returns full name successfully
Log.i(TAG, person.getGender()); //0
Log.i(TAG, person.getBirthday()); //null
}
}
}
我也尝试从帐户 (GoogleSignInAccount account = result.getSignInAccount()) 中获取它,但据我搜索,此变量根本不拥有请求的数据。
我错过了什么吗?或者,尽管有明确的请求,但可能无法获取私有数据?
谢谢。
顺便说一句,我还没有尝试过私人性别的场景。
【问题讨论】:
标签: android google-play-services google-plus google-signin google-plus-signin