2016-04-25 57 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

当您授权范围,浏览器会保存您的会话。因此,如果您再次在同一个浏览器中授权应用程序,则只会将范围显示为已离线访问

相关问题