2

I am able to get username and email into my app using the follow code, but gender,birthday and location are returning to be null.

// Initializing google plus api client
        mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Plus.API)
        .addScope(Plus.SCOPE_PLUS_LOGIN)
        .addScope(Plus.SCOPE_PLUS_PROFILE)
        .build();

this is onActivityResult() method

@Override
    protected void onActivityResult(int requestCode, int responseCode,Intent intent) {
        super.onActivityResult(requestCode, responseCode, intent);
        if (requestCode == RC_SIGN_IN) {
            if (responseCode != RESULT_OK) {
                mSignInClicked = false;
            }

            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
                mGoogleApiClient.connect();
            }
        }
        //fb callback
        callbackManager.onActivityResult(requestCode, responseCode, intent);
    }

This is onConnected() method

   @Override
    public void onConnected(Bundle arg0) {

        mSignInClicked = false;
        Log.e("on connected","on connected");
        try {
            if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {

                Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

                String personName = currentPerson.getDisplayName();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
                int gender = currentPerson.getGender();
                String birthdate = currentPerson.getBirthday();
                String location = currentPerson.getCurrentLocation();
                Log.e(TAG, "Name: " + personName + ", email: " + email+ ", Gender: " + gender + ", Birthday: " + birthdate + ",Location" + location );

            } else {
                Toast.makeText(getApplicationContext(),
                        "Person information is null", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
        Intent i = new Intent(LoginActivity.this , Categories.class);
        finish();
        startActivity(i);

    }

And this is the response that i am getting after onConnected()

06-18 15:01:12.258: E/LoginActivity(28307): Name: karan mer, email: karan.mer@gmail.com, Gender: 0, Birthday: null,Locationnull
karan
  • 8,637
  • 3
  • 41
  • 78

0 Answers0