title: com.google.android.gms.common.api.ApiException: 4 and ...ApiException: 5000: Application needs OAuth consent from the user
body: <p>i'm trying to connect to google fit and exchange the health data with its from my app.
  Here my code:</p>
  <pre><code>            if (!GoogleSignIn.hasPermissions(
                      GoogleSignIn.getLastSignedInAccount(getContext()),
                      new Scope(Scopes.FITNESS_BLOOD_GLUCOSE_READ_WRITE)
              )) {
                  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                          .requestEmail()
                          .requestScopes(new Scope(Scopes.FITNESS_BLOOD_GLUCOSE_READ_WRITE))
                          .build();
                  GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this.getContext(), gso);
  
              
                  Intent signInIntent = mGoogleSignInClient.getSignInIntent();
                  startActivityForResult(signInIntent, RC_SIGN_IN);
              }
  
              if (!GoogleSignIn.hasPermissions(
                      GoogleSignIn.getLastSignedInAccount(getContext()),
                      new Scope(Scopes.FITNESS_BLOOD_GLUCOSE_READ_WRITE)
              ))
              {
                  Log.e(&quot;GOOGLE_FIT&quot;, &quot;no permission&quot;);
  
                  GoogleSignIn.requestPermissions(
                          this, 
                          GOOGLE_FIT_PERMISSIONS_REQUEST_CODE,
                          GoogleSignIn.getLastSignedInAccount(getContext()),
                          new Scope(Scopes.FITNESS_BLOOD_GLUCOSE_READ_WRITE)
                  );
  
  
              } else {
  
                  accessGoogleFit();
              }
  </code></pre>
  <p>and the method access GoogleFit():</p>
  <pre><code>private void accessGoogleFit() {
      final  String LOG_TAG=&quot;i am here&quot;;
      Calendar cal = Calendar.getInstance();
      cal.setTime(new Date());
      long endTime = cal.getTimeInMillis();
      cal.add(Calendar.YEAR, -1);
      long startTime = cal.getTimeInMillis();
  
      DataReadRequest readRequest = new DataReadRequest.Builder()
              .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
              .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
              .bucketByTime(1, TimeUnit.DAYS)
              .build();
  
  
      Fitness.getHistoryClient(this.getContext(), GoogleSignIn.getLastSignedInAccount(this.getActivity()))
              .readData(readRequest)
              .addOnSuccessListener(new OnSuccessListener() {
                  @Override
                  public void onSuccess(Object o) {
                      Log.d(LOG_TAG, &quot;onSuccess()&quot;);
                  }
  
  
              })
              .addOnFailureListener(new OnFailureListener() {
                  @Override
                  public void onFailure(@NonNull Exception e) {
                      Log.e(LOG_TAG, &quot;onFailure()&quot;, e);
                  }
              })
              .addOnCompleteListener(new OnCompleteListener() {
                  @Override
                  public void onComplete(@NonNull Task task) {
                      Log.d(LOG_TAG, &quot;onComplete()&quot;);
                  }
              });
  }
  </code></pre>
  <p>When execute the i recive this error:</p>
  <blockquote>
  <p>onFailure()
  com.google.android.gms.common.api.ApiException: 5000: Application needs OAuth consent from the user
  at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@17.1.0:4)
  at com.google.android.gms.common.internal.zai.zaf(com.google.android.gms:play-services-base@@17.1.0:2)
  at com.google.android.gms.common.internal.zak.onComplete(com.google.android.gms:play-services-base@@17.1.0:6)
  at com.google.android.gms.common.api.internal.BasePendingResult.zaa(com.google.android.gms:play-services-base@@17.1.0:176)
  at com.google.android.gms.common.api.internal.BasePendingResult.setResult(com.google.android.gms:play-services-base@@17.1.0:135)
  at com.google.android.gms.internal.fitness.zzae.setResult(com.google.android.gms:play-services-fitness@@20.0.0:3)
  at com.google.android.gms.internal.fitness.zzdp.zza(com.google.android.gms:play-services-fitness@@20.0.0:13)
  at com.google.android.gms.internal.fitness.zzbf.zza(com.google.android.gms:play-services-fitness@@20.0.0:11)
  at com.google.android.gms.internal.fitness.zza.onTransact(com.google.android.gms:play-services-fitness@@20.0.0:13)
  at android.os.Binder.execTransactInternal(Binder.java:1021)
  at android.os.Binder.execTransact(Binder.java:994)</p>
  </blockquote>
  <p>I followed the step in <a href="https://developers.google.com/fit/android/get-started" rel="nofollow noreferrer">https://developers.google.com/fit/android/get-started</a>.</p>
  <p>Plese help me and say me what i'm doing wrong?</p>
  <p>Thank you to evreyone!</p>