2016-04-25 55 views
0

我創建了一個新的應用程序,GoogleFit的身份驗證部分是另一個完美工作的應用程序的完整複製/粘貼。出現選擇帳戶的窗口,但在此之後,我期待看到顯示所需範圍但沒有任何內容的窗口。授權範圍不出現

有沒有人遇到過這個問題?

如果需要,我可以發佈我的代碼。

非常感謝!

編輯

這是我的代碼連接到谷歌飛度:

private void buildFitnessClient() { 
    // Create the Google API Client 
     mFitClient = new GoogleApiClient.Builder(this) 
       .addApi(Fitness.HISTORY_API) 
       .addApi(Fitness.RECORDING_API) 
       .addApi(Fitness.CONFIG_API) 
       .addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) 
       .addScope(new Scope((Scopes.FITNESS_NUTRITION_READ_WRITE))) 
       .addScope(new Scope(Scopes.FITNESS_BODY_READ_WRITE)) 
       .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { 
              @Override 
              public void onConnected(Bundle bundle) { 
               Log.i(TAG, "Connected to Fitness API!!!"); 
               // Now you can make calls to the Fitness APIs. 
               // Put application specific code here. 
               // Once connected go the Main2Activity 
               Intent start_google_plus = new Intent(GoogleFitAuthentication.this, MainActivity.class); 
               startActivity(start_google_plus); 
               finish(); 
              } 

              @Override 
              public void onConnectionSuspended(int i) { 
               Log.i(TAG, "onConnectionSuspend"); 
               // If your connection to the sensor gets lost at some point, 
               // you'll be able to determine the reason and react to it here. 
               if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) { 
                Log.i(TAG, "Connection lost. Cause: Network Lost."); 
               } else if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) { 
                Log.i(TAG, "Connection lost. Reason: Service Disconnected"); 
               } 
              } 
             } 
       ) 
       .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { 
                // Called whenever the API client fails to connect. 
                @Override 
                public void onConnectionFailed(ConnectionResult result) { 
                 Log.i(TAG, "Connection failed. Cause: " + result.toString()); 
                 if (!result.hasResolution()) { 
                  // Show the localized error dialog 
                  GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), 
                    GoogleFitAuthentication.this, 0).show(); 
                  return; 
                 } 
                 // The failure has a resolution. Resolve it. 
                 // Called typically when the app is not yet authorized, and an 
                 // authorization dialog is displayed to the user. 
                 if (!authInProgress) { 
                  try { 
                   Log.i(TAG, "Attempting to resolve failed connection"); 
                   authInProgress = true; 
                   result.startResolutionForResult(GoogleFitAuthentication.this, REQUEST_OAUTH); 
                  } catch (IntentSender.SendIntentException e) { 
                   Log.e(TAG, "Exception while starting resolution activity", e); 
                  } 
                 } 
                } 
               } 
       ) 
       .build(); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    Log.d(TAG, "Processing onActivityResult..."); 
    if (requestCode == REQUEST_OAUTH) { 
     Log.d(TAG, "requestCode == REQUEST_OAUTH"); 
     authInProgress = false; 
     if (resultCode == RESULT_OK) { 
      Log.d(TAG, "resultCode == RESULT_OK"); 
      // Make sure the app is not already connected or attempting to connect 
      if (!mFitClient.isConnecting() && !mFitClient.isConnected()) { 
       mFitClient.connect(); 
      } 
     } 
    }else{ 
     Log.d(TAG, "Impossible to process onActivityResult..."); 
    } 
} 

@Override 
protected void onStart() { 
    super.onStart(); 
    // Connect to the Fitness API 
    Log.i(TAG, "Connecting..."); 
    if(mFitClient!=null){ 
     mFitClient.connect(); 
    } 
} 

@Override 
protected void onStop() { 
    super.onStop(); 
    Log.i(TAG, "onStop..."); 
    if (mFitClient!=null && mFitClient.isConnected()) { 
     mFitClient.disconnect(); 
    } 
} 

@Override 
protected void onSaveInstanceState(@NonNull Bundle outState) { 
    super.onSaveInstanceState(outState); 
    outState.putBoolean(AUTH_PENDING, authInProgress); 
} 
+0

先顯示您的複製/粘貼代碼...也許您已經複製了一些應用程序ID ... –

+1

我找到了問題。在谷歌api控制檯中有一個包名錯誤! –

回答

0

當您授權範圍,瀏覽器會保存您的會話。因此,如果您再次在同一個瀏覽器中授權應用程序,則只會將範圍顯示爲已離線訪問

相關問題