如何将生日,地点和性别从Google+转换为Android应用

时间:2015-06-18 09:44:02

标签: android google-plus google-login

我可以使用以下代码将用户名和电子邮件发送到我的应用中,但性别,生日和地点返回为空。

{{ product.definition|trans }}

这是onActivityResult()方法

// 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();

这是onConnected()方法

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

这是我在onConnected()

之后得到的回应
   @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);

    }

0 个答案:

没有答案