简体   繁体   中英

How to get gender from GoogleSignInAccount (previous method is now deprecated)

Plus.PeopleApi.load(mGoogleApiClient, googleUser.getId()).setResultCallback(new ResultCallback<People.LoadPeopleResult>() {
            @Override
            public void onResult(@NonNull People.LoadPeopleResult loadPeopleResult) {
                Person person = loadPeopleResult.getPersonBuffer().get(0);
                gender = person.getGender();
                loadPeopleResult.release();
            }
        });

This is the code I used until now to get gender from GoogleSignInAccount, which is currently the proper way of implementing Google sign in into Android apps. But since the 9.4.0 update for the com.google.android.gms:play-services-plus, the whole Plus class is deprecated, including the PeopleApi and load method. I've read tons of Google documentation, but I just can't find a proper way to get gender.

Yes Plus is deprecated.

Have you tried the package: com.google.android.gms.plus.model.people I think this could be the documentation you're looking for: https://developers.google.com/android/reference/com/google/android/gms/plus/model/people/package-summary

There you can see they changed the API to plus.model.people and a subclass is Person.Gender . Then the method that is specified for gender is:
getGender() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM