代码之家  ›  专栏  ›  技术社区  ›  Abhishek Chaniyara

不推荐使用Google Plus API。如何从RequestScope(scope(scopes.profile))中获取性别和出生日期?

  •  1
  • Abhishek Chaniyara  · 技术社区  · 6 年前

    不推荐使用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()
                }
    
            }
        }
    
    1 回复  |  直到 5 年前
        1
  •  2
  •   Saurabh Verma    5 年前

    由于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}