不推荐使用Google Plus API。我如何从请求范围获得性别和出生日期。下面是我的代码:
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("xxxxxxxxx.apps.googleusercontent.com")
.requestEmail()
.requestProfile()
.requestScopes(Scope(Scopes.PROFILE))
.build()
val mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
在此登录选项中,我想要Google用户的性别和生日。
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
callbackManager.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val result = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = result.getResult(ApiException::class.java)
//Here I want gender and date of birth from google sign in option
} catch (e: ApiException) {
e.printStackTrace()
}
}
}
答案 0 :(得分:2)
由于不建议使用google plus api,因此我们必须将应用程序从google plus身份验证迁移到Google Auth。您的问题的解决方案如下。 Google的People API对您获取所需的详细信息会有所帮助 link
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/contacts
https://www.googleapis.com/auth/contacts.readonly
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/profile.agerange.read
https://www.googleapis.com/auth/profile.language.read
https://www.googleapis.com/auth/user.addresses.read
https://www.googleapis.com/auth/user.birthday.read
https://www.googleapis.com/auth/user.phonenumbers.read
https://www.googleapis.com/auth/user.emails.read
您需要确切要求您要哪些字段。 “性别”和“出生日期”字段可能对您来说最重要,但还有其他可用的字段。您将获得一个可能值的数组,每个值指示其来源。您可能会想要“ PROFILE”的源类型,但是您当然可以评估其他类型。
因此,如果您发出的请求是
GET https://people.googleapis.com/v1/people/101852559274654726533?personFields=gender%2Cbirthdate&key={YOUR_API_KEY}