获取新的谷歌标志的人细节播放服务8.3 [英] Get person details in new google sign in Play Services 8.3

查看:308
本文介绍了获取新的谷歌标志的人细节播放服务8.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让使用新谷歌登录API中播放业务介绍8.3用户的个人资料。除了显示姓名,电子邮件和身份证,我还需要用户的性别。

I'm trying to get a user's profile using the new Google Sign In API introduced in play services 8.3. Other than Display Name, Email and Id, I also need user's gender.

Plus.PeopleApi.getCurrentPerson() 

是pcated按播放服务8.3代$ P $,也为我返回null即使

is deprecated as per play services 8.3 and also returns null for me even though

mGoogleApiClient.hasConnectedApi(Plus.API) 

返回true。

returns true.

GoogleSignInAccount.getGrantedScopes 

返回

https://www.googleapis.com/auth/plus.me
https://www.googleapis.com/auth/plus.login
profile
email
openid

谷歌开发者控制台不会显示在Google+ API的任何命中。我已经把正确的谷歌,services.json文件中的应用程序/文件夹。我甚至产生的SHA1指纹编程方式来验证,如果我使用了正确的密钥库。

Google Developer Console doesn't show any hits on the Google+ API. I have placed the correct google-services.json file in app/ folder of application. I even generated the SHA1 fingerprint programatically to verify if I was using the correct keystore.

我怎样才能获得谷歌的人+配置文件数据(性别,姓氏,给定的名称等)使用新的登录API?

How can I get the person google+ profile data (gender, family name, given name etc.) using the new sign in API?

推荐答案

IMO,你可以参考以下code:

IMO, you can refer to the following code:

        // [START configure_signin]
        // Configure sign-in to request the user's ID, email address, and basic
        // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
        // FOR PROFILE PICTURE:
        // Ref: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount.html#getPhotoUrl%28%29
        // getPhotoUrl(): Gets the photo url of the signed in user.
        // Only non-null if requestProfile() is configured and user does have a Google+ profile picture.
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PROFILE))
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .requestProfile()
                .requestEmail()
                .build();
        // [END configure_signin]

        // [START build_client]
        // Build a GoogleApiClient with access to the Google Sign-In API and the
        // options specified by gso.
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addApi(Plus.API)
                .build();
        // [END build_client]

然后:

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);

            Person person  = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);            
            Log.i(TAG, "Gender: " + person.getGender());
        }
    }

logcat的信息:

Logcat info:

11-20 09:06:35.431 31289-31289/com.example.googlesignindemo I/GoogleSignIn: Gender: 0

希望这有助于!

这篇关于获取新的谷歌标志的人细节播放服务8.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆