如何使用google plus集成中的此范围获取电子邮件地址

时间:2014-09-26 10:15:29

标签: android gmail google-plus gmail-api

我在android oauth中尝试了这个网址https://www.googleapis.com/auth/userinfo.profile,而在我的应用程序中使用google plus integration。

获取以下json和此json数组不包含该电子邮件     像这样的地址

profile{"displayName":"Devarajan Mahalingam","gender":"male",
"id":"101222514586833333269",
"image":{"url":"https://"}

我正在获取除电子邮件地址以外的所有详细信息。我需要获取电子邮件地址..

4 个答案:

答案 0 :(得分:1)

使用以下行获取使用GoogleApiClient的电子邮件地址

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

答案 1 :(得分:1)

您需要像这样解析范围

String SCOPE =" https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";

答案 2 :(得分:0)

答案 3 :(得分:0)

你是否Checked这个?希望这可以帮助。

private void getProfileInformation() {
    try {
        if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {

            Person currentPerson = Plus.PeopleApi
                    .getCurrentPerson(mGoogleApiClient);
            String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
            String personName = currentPerson.getDisplayName();
            String personPhotoUrl = currentPerson.getImage().getUrl();
            String personGooglePlusProfile = currentPerson.getUrl();


            Log.e(TAG, "Name: " + personName + ", plusProfile: "
                    + personGooglePlusProfile + ", email: " + email
                    + ", Image: " + personPhotoUrl);

            txtName.setText(personName);
            txtEmail.setText(email);

            // by default the profile url gives 50x50 px image only
            // we can replace the value with whatever dimension we want by
            // replacing sz=X
            personPhotoUrl = personPhotoUrl.substring(0,
                    personPhotoUrl.length() - 2)
                    + PROFILE_PIC_SIZE;

            new LoadProfileImage(imgProfilePic).execute(personPhotoUrl);

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