0

I want to add google signin in my android app. And after that I want to retrieve the user's data like "gender","date of birth" etc. Here is what I have done so far.

public class MyActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener,GoogleApiClient.ConnectionCallbacks, ResultCallback<People.LoadPeopleResult> {



GoogleApiClient mGoogleApiClient;
SignInButton signInButton;

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .requestScopes(new Scope(Scopes.PLUS_ME))
                .build();


mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /*FragmentActivity*/, this /*OnConnectionFailedListener*/)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addApi(Plus.API, Plus.PlusOptions.builder().build())
                .build();




 signInButton = (SignInButton) findViewById(R.id.sign_in_button);



        signInButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                signIn();
            }
        });

    }

    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }


    @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);
        }
    }

    private void handleSignInResult(GoogleSignInResult result) {
        Log.d("Signin", "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {

            // Signed in successfully, show authenticated UI.
            final GoogleSignInAccount acct = result.getSignInAccount();
            Log.d("Signin",acct.getDisplayName()+" "+acct.getEmail());
            Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
            Log.d("Person", currentPerson.getBirthday());




        } else {
            // Signed out, show unauthenticated UI.
            //updateUI(false);
        }
    }


    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

    }

    @Override
    public void onConnected(Bundle bundle) {

    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onResult(People.LoadPeopleResult loadPeopleResult) {

    }
}

I am able to get the user's name and email-id but I am not able to get user's birthday. The code

Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
Log.d("Person", currentPerson.getBirthday());

throws error.

Error :- Appropriate API not request.

I have tried adding Persosn to "mGoogleApiClient" but failed to get results.

Please help.

  • Maybe you are missing a library? This question might help bring light on the issue: https://stackoverflow.com/questions/29190072/android-activityrecognition-java-lang-nullpointerexception-appropriate-api-was – Acapulco Jan 22 '16 at 17:13
  • Thanks for your comment... but which API do i need to get the user's gender and date of birth information. ... Auth.GOOGLE_SIGN_IN_API and Plus.API .. do I need anything else – Riju Chetry Jan 22 '16 at 17:35

0 Answers0