在我的应用程序中,我正在使用Google Plus集成.另外访问Google帐户详细信息包括用户名,个人资料图片等.但这些用户详细信息有时会返回空值.请帮我找原因.
这是我的代码:
mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this) .addConnectionCallbacks(MainActivity.this) .addOnConnectionFailedListener(MainActivity.this).addApi(Plus.API,Plus.PlusOptions.builder().build()) .addScope(Plus.SCOPE_PLUS_LOGIN) .addScope(Plus.SCOPE_PLUS_PROFILE) .addApi(AppIndex.API).build();
在onConnected()中:
@Override public void onConnected(Bundle bundle) { String personName="Unknown"; gmail = Plus.AccountApi.getAccountName( (GoogleApiClient) mGoogleApiClient).toString(); try { String[] id = gmail.split("@"); try { plusid = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient).getId(); } catch (NullPointerException e) { plusid = id[0]; } plusimage = Plus.PeopleApi .getCurrentPerson((GoogleApiClient) mGoogleApiClient) .getImage().getUrl().toString(); plusname = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient).getDisplayName().toString(); } if (CheckNetworkConnection.isConnectionAvailable(MainActivity.this)) { // new SocialLogin().execute(); } } catch (NullPointerException e) { Toast.makeText(getApplicationContext(), "GMAIL" + gmail, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "ID" +plusid , Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "NAME" + plusname, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "IMG" + plusimage, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Google plus account not configured correctly", Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }
这里plusimage和plusname返回null.请帮我找原因.