2016-01-06 9 views
6

In meiner Anwendung verwende ich Google Plus-Integration. Greifen Sie auch auf die Details des Google-Kontos zu, einschließlich Nutzername, Profilbild usw. Diese Nutzerdaten geben jedoch manchmal einen Nullwert zurück. Bitte hilf mir den Grund zu finden.Android Google + Integration gibt manchmal Nullwerte zurück

Dies ist mein Code:

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

und in 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(); 
       } 
      } 

hier plusimage und plusname Rückkehr null.Please mir helfen, den Grund zu finden.

+0

Ohne uns einen Code zur Verfügung zu stellen, wird es ziemlich schwierig zu finden, wo in Ihrem Code das Problem herkommt. Bitte lesen Sie diese Dokumentation - http://stackoverflow.com/help/how-to-ask - bevor Sie eine Frage stellen. – jeffdill2

+0

@ jeffdill2 Sorry.Question Edited – krishna

+0

@ Krishna Verwenden Sie dieses Beispiel als Referenz möglicherweise funktioniert es für Sie .. https://github.com/googlesamples/google-services/blob/master/android/signin/app/src/main /java/com/google/samples/quickstart/signin/SignInActivity.java#L51-L55 –

Antwort

1

Diese Zeile hinzufügen.

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

mögen.

public void onConnected(Bundle connectionHint) {  

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

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

für weitere Informationen. lesen Documentation

+0

Dies gibt auch null Wert – krishna

+0

@ krishna Ist SHA1 das gleiche zwischen Ihrer App und der Google-Konsole? –

+0

ja, beide sind gleich. – krishna

Verwandte Themen