在Android fetch中集成googleplus(性别和生日)

时间:2015-01-12 18:23:30

标签: java android google-plus

我正试图从Android中的googleplus集成中获取性别和生日...     但是将性别设为“0”请帮我解决这个..我附上我的代码..请找下面的内容     code..birthday显示为空..

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    mSignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

              mGoogleApiClient.connect();

        }
    });


    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .addScope(Plus.SCOPE_PLUS_LOGIN).build();
}

protected void onStart() {
    super.onStart();
//  mGoogleApiClient.connect();



}

protected void onStop() {
    super.onStop();

    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}

public void onConnectionFailed(ConnectionResult result) {
    if (!mIntentInProgress && result.hasResolution()) {
        try {
            mIntentInProgress = true;
            startIntentSenderForResult(result.getResolution()
                    .getIntentSender(), RC_SIGN_IN, null, 0, 0, 0);
        } catch (SendIntentException e) {

            mIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
}



public void onConnected(Bundle connectionHint) {

    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {

        Person currentPerson = Plus.PeopleApi
                .getCurrentPerson(mGoogleApiClient);
        String personName = currentPerson.getDisplayName();         

        try {
            int genderInt = currentPerson.getGender();
         String   gender     = String.valueOf(genderInt);
        String birthday = currentPerson.getBirthday();

        System.out.println("gender" + gender + "bod" + birthday);

        } 


        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       

        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    }
}

@Override
public void onConnectionSuspended(int cause) {
    mGoogleApiClient.connect();
}

protected void onActivityResult(int requestCode, int responseCode,
        Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        mIntentInProgress = false;

        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    }
}



@Override
public void onResult(LoadPeopleResult peopleData) {
    // TODO Auto-generated method stub
     if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) {
            PersonBuffer personBuffer = peopleData.getPersonBuffer();
            try {
              int count = personBuffer.getCount();
              for (int i = 0; i < count; i++) {
                Log.d(TAG, "Display name: " + personBuffer.get(i).getDisplayName());
              }
            } finally {
              personBuffer.close();
            }
          } else {
            Log.e(TAG, "Error requesting people data: " + peopleData.getStatus());
          }
}

}

1 个答案:

答案 0 :(得分:5)