droidster droidster - 1 year ago 345
Android Question

Plus.PeopleApi.getCurrentPerson deprecated in Play services 8.4. How to get user's first name, last name and gender using GoogleSignInApi?

With Play services 8.4, the method getCurrentPerson is deprecated and I was using the PeopleApi to get user's first name, last name and gender.

Can anyone tell me how to get the signed in user's info using another method?

Answer Source

I found the solution myself so I'm posting it here if anyone else faces the same problem.

Although I was looking for a solution for using GoogleSignInApi to get user's info, I couldn't find that and I think we need to use the Plus Api to get info like gender.

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);


private void handleSignInResult(GoogleSignInResult result)
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess())
            GoogleSignInAccount acct = result.getSignInAccount();

             Plus.PeopleApi.load(mGoogleApiClient, acct.getId()).setResultCallback(new ResultCallback<People.LoadPeopleResult>() {
                public void onResult(@NonNull People.LoadPeopleResult loadPeopleResult) {
                    Person person = loadPeopleResult.getPersonBuffer().get(0);
                    Log.d(TAG,"Person loaded");
                    Log.d(TAG,"GivenName "+person.getName().getGivenName());
                    Log.d(TAG,"FamilyName "+person.getName().getFamilyName());
                    Log.d(TAG,("DisplayName "+person.getDisplayName()));
                    Log.d(TAG,"Gender "+person.getGender());
                    Log.d(TAG,"Url "+person.getUrl());
                    Log.d(TAG,"CurrentLocation "+person.getCurrentLocation());
                    Log.d(TAG,"AboutMe "+person.getAboutMe());
                    Log.d(TAG,"Birthday "+person.getBirthday());
                    Log.d(TAG,"Image "+person.getImage());

            //mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
        } else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download