【问题标题】:Google Plus API is Deprecated. How do i get gender and birth date from requestScopes(Scope(Scopes.PROFILE))Google Plus API 已弃用。如何从 requestScopes(Scope(Scopes.PROFILE)) 获取性别和出生日期
【发布时间】:2018-11-21 05:59:42
【问题描述】:

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()
            }

        }
    }

【问题讨论】:

    标签: android kotlin google-signin


    【解决方案1】:

    由于不推荐使用 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}
    

    【讨论】:

    • 这就是我要找的东西谢谢你先生
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    相关资源
    最近更新 更多