不建议使用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)
从这个登录选项,我想要谷歌用户的性别和生日。
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()
}
}
}
由于不建议使用google plus api,因此我们必须将应用程序从google plus身份验证迁移到Google Auth。解决问题的方法如下。Google的People API将对您获取所需的详细信息链接有所帮助
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}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句