2016-08-26 55 views
1

美好的一天。我正在嘗試調用api方法。一切順利,登錄屏幕正在向用戶顯示其圈子的請求,並繁榮只要我嘗試從圈子中獲取人員列表,它總會出錯!Google Android人員錯誤狀態{statusCode = NETWORK_ERROR,resolution = null}

Status{statusCode=NETWORK_ERROR, resolution=null} 

我不知道是什麼引起,並通過google搜索,我發現沒有接近我的問題,所以生病後的代碼中,我該怎麼辦調用此方法。 這裏我如何構建和調用它。

public synchronized GoogleApiClient buildGoogleApiClient(final Activity activity) { 
    GoogleSignInOptions gGoogleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
      .requestScopes(new Scope(Scopes.PROFILE)) 
      .requestScopes(new Scope(Scopes.PLUS_LOGIN)) 
      .requestProfile() 
      .requestEmail() 
      .build(); 

    mGoogleApiClient = new GoogleApiClient.Builder(activity) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gGoogleSignInOptions) 
      .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { 
       @Override 
       public void onConnected(@Nullable Bundle bundle) { 
        Plus.PeopleApi.loadVisible(mGoogleApiClient, "me").setResultCallback(new ResultCallbacks<People.LoadPeopleResult>() { 
         @Override 
         public void onSuccess(@NonNull People.LoadPeopleResult loadPeopleResult) { 
          Toast.makeText(activity, "", Toast.LENGTH_SHORT).show(); 
          Person person = loadPeopleResult.getPersonBuffer().get(0); 
          Log.d("fasfafasfsafasfas", "onSuccess: " + person); 
         } 

         @Override 
         public void onFailure(@NonNull Status status) { 
          if (status.hasResolution()) { 
           try { 
            // !!! 
            status.startResolutionForResult(activity, 100); 
           } catch (IntentSender.SendIntentException e) { 
            mGoogleApiClient.connect(); 
           } 
          } 
          Log.d("fasfafasfsafasfas", "onFailure: " + status); 
         } 

        }); 

       } 

       @Override 
       public void onConnectionSuspended(int i) { 
        Toast.makeText(activity, "fail", Toast.LENGTH_SHORT).show(); 
       } 
      }) 
      .addApi(Plus.API) 
      .build(); 
    mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL); 
    return mGoogleApiClient; 
} 

它總是進入onFailure處回調與網絡error..I不知道什麼是錯我已經輸入... 在這裏表現

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" /> 
<uses-permission android:name="android.permission.READ_PROFILE" /> 
需要的權限

所以,請你告訴我,什麼是錯用我的代碼?

+0

傢伙????沒有人有線索? –

+0

您是否閱讀過[this](http://stackoverflow.com/questions/15195264/google-plus-unable-to-load-person)?爲什麼沒有幫助? –

+0

因爲所有api鍵設置正確 –

回答

0

如果有人碰到同樣的問題,這裏是solution.You不需要指定「我」越來越圈時,同時指定NULL來像這樣

Plus.PeopleApi.loadVisible(mGoogleApiClient, null 
        ).setResultCallback(new ResultCallbacks<People.LoadPeopleResult>() { 
         @Override 
         public void onSuccess(@NonNull People.LoadPeopleResult loadPeopleResult) { 
          int personCount = loadPeopleResult.getPersonBuffer().getCount(); 
          Log.d("fasfafasfsafasfas", "onSuccess: " + personCount); 
          for (int i = 0; i < personCount; i++) { 
           Person eachPerson = loadPeopleResult.getPersonBuffer().get(i); 
           Log.d("fasfafasfsafasfas", "onSuccess: " + eachPerson.getImage().getUrl()); 
          } 
         } 

         @Override 
         public void onFailure(@NonNull Status status) { 
          if (status.hasResolution()) { 
           try { 
            status.startResolutionForResult(activity, requestCode); 
           } catch (IntentSender.SendIntentException e) { 
            mGoogleApiClient.connect(); 
           } 
          } 
          Log.d("fasfafasfsafasfas", "onFailure: " + status); 
         } 

        }); 
相關問題