来自google plus的用户名返回null

时间:2015-06-22 07:01:00

标签: android google-api google-plus

public void onConnected(Bundle connectionHint) {

      String personName="Unknown";
    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
       Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
       personName = currentPerson.getDisplayName();
       .........
    }
}

我已经尝试了所有可能性

Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);

我加倍检查了SHA密钥和google-service-key generation。

但它返回Null。

1 个答案:

答案 0 :(得分:0)

尝试这样做会起作用

private void getProfileInformation() {
        try {
            if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
                Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
                String personName = currentPerson.getDisplayName();
                String personPhotoUrl = currentPerson.getImage().getUrl();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

                username.setText(personName);
                emailLabel.setText(email);

                new LoadProfileImage(image).execute(personPhotoUrl);

                // update profile frame with new info about Google Account
                // profile
                updateProfile(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

link for reference

参考上面的链接登录,注销,个人资料信息工作正常。