如何获取用户displayName和谷歌帐户的头像?

时间:2015-05-21 18:28:16

标签: android google-api google-account

我有GoogleAccountCredential对象,可以收到用户的电子邮件。但是,我需要获取他的displayName和头像图标的url。帮你做这个吗?

我通过此代码获得的GoogleAccountCredential对象:

 credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(CalendarScopes.CALENDAR));

它需要我获取谷歌日历。

1 个答案:

答案 0 :(得分:1)

private void getProfileInformation() {
        try {
            if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
                Person currentPerson = Plus.PeopleApi
                        .getCurrentPerson(mGoogleApiClient);
                String personName = currentPerson.getDisplayName().replace(" ", "%20");
                String personPhotoUrl = currentPerson.getImage().getUrl();
                // String personGooglePlusProfile = currentPerson.getUrl();
                // int gender = currentPerson.getGender();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

                // Log.i("personName", ""+personName);



            } else {
                Toast.makeText(getApplicationContext(),
                        "Person information is null", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }