2016-04-15 9 views
0

私のアプリケーションにgoogle + loginを使用しています。 初めてのユーザーはログインしています。ユーザーがログアウトしていて、同じユーザーが再度ログインしようとすると、 Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)がnullです。eclipseでGoogle PlusとAndroidを統合する際にエラーが発生する

このエラーを解決する方法。

public void onConnected(Bundle connectionHint) {   

    // Reaching onConnected means we consider the user signed in. 
    // Update the user interface to reflect that the user is signed in. 
    // Retrieve some profile information to personalize our app for the 
    // user. 

    Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(null); 
    Person currentUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); 

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

    if (currentUser == null) { 
     Utils.signOutAndDisconnect(mGoogleApiClient); 
     if (isGooglePlusClicked) { 
      isGooglePlusClicked = false; 
      Toast.makeText(
        this, 
        "Google sign-in is not available for now. " 
          + "Please try again later.", Toast.LENGTH_SHORT) 
          .show(); 
     } 
     return; 
    } 

    Log.i(TAG, "g+ onConnected isSignInClicked currentUser=" + currentUser); 
    BaseWebServiceRunner webServiceRunner = new BaseWebServiceRunner(this); 

    Log.i(TAG, "g+ onConnected isGooglePlusClicked value=" + isGooglePlusClicked); 

    if (isGooglePlusClicked) { 
     isGooglePlusClicked = false; 
     if (edit_username.getVisibility() == View.VISIBLE) { 
      User user = new User(); 
      user.setFname(currentUser.getDisplayName()); 
      UserGoogle usergoogle = new UserGoogle(); 
      usergoogle.setAbout_me(currentUser.getAboutMe()); 
      usergoogle.setBirthdate(currentUser.getBirthday()); 
      switch (currentUser.getGender()) { 
      case 1: 
       usergoogle.setGender("FEMALE"); 
       user.setGender("FEMALE"); 
       break; 
      case 0: 
       usergoogle.setGender("MALE"); 
       user.setGender("MALE"); 
       break; 
      default: 
       usergoogle.setGender("OTHER"); 
       user.setGender("OTHER"); 
       break; 
      } 

      Image image = currentUser.getImage(); 
      if (image != null && image.hasUrl()) { 
       // by default the profile url gives 50x50 px image only 
       // we can replace the value with whatever dimension we want 
       // by 
       // replacing sz=X 
       String actualUrl = image.getUrl(); 
       String url = actualUrl.substring(0, actualUrl.length() - 2) 
         + Prefs.SCALE_BITMAP_WIDTH; 
       user.setPicture(url); 
      } 

      usergoogle.setLogin_name(email); 
      user.setGoogle(usergoogle); 
      user.setEmail(email); 
      user.setUsername(email); 
      user.setPassword("123456"); 
      user.setRegister_by(UserLoginType.Google.toString()); 

      user.setAddress1(SharedPreferenceConnector.readString(this, Prefs.ADDRESS_LINE_0, "")); 
      user.setAddress2(SharedPreferenceConnector.readString(this, Prefs.ADDRESS_LINE_1, "")); 
      user.setCity(SharedPreferenceConnector.readString(this, Prefs.CITY_NAME, "")); 
      user.setState(SharedPreferenceConnector.readString(this, Prefs.STATE_NAME, "")); 
      user.setCountry(SharedPreferenceConnector.readString(this, Prefs.COUNTRY_NAME, "")); 

      //    user.setDevice_id(Utility.getDeviceId(this)); 

      UserRegistrationWS registrationWS = new UserRegistrationWS(
        this, user, UserRegistrationType.NEW); 
      UserRegistrationWS[] params = new UserRegistrationWS[1]; 
      params[0] = registrationWS; 
      webServiceRunner.execute(params); 
     } 
    } else { 
     Utils.signOutAndDisconnect(mGoogleApiClient); 
    } 
    gServicesSignInProg = STATE_DEFAULT; 
} 
+0

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

を置き換えますか?コードなしの –

+0

どうすれば誰かを助けることができますか? –

答えて

0

あなたのコードを共有することができ

Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this); 
関連する問題