title: How do I get the steps from Google Fit API?
body: <p>Pardon noobiness, I am completely new to Android, and Google APIs. I have the following code that connects to GoogleFit. I also have an API key and Oauth.</p>
  
  <p>Where/how do i use API key and Oauth? Lots of guides on how to obtain them but zero info on where to put them/how to use them in the app.</p>
  
  <p>And how do I actually use the  steps returned. I set up a global:</p>
  
  <pre><code>private int steps;
  </code></pre>
  
  <p>and then try to set it via:</p>
  
  <pre><code>steps = (int)total;
  </code></pre>
  
  <p>but it does nothing.</p>
  
  <p>Here is the rest of the function. How do I actually get the step count out of it.</p>
  
  <pre><code> private void accessGoogleFit() {
          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)
                  .bucketByTime(1, TimeUnit.DAYS)
                  .setTimeRange(starttime, endtime, TimeUnit.MILLISECONDS)
                  .build();
  
          Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this))
                  .readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)
                  .addOnSuccessListener(new OnSuccessListener&lt;DataSet&gt;() {
                      @Override
                      public void onSuccess(DataSet dataSet) {
                          Log.d("Status", "Success");
                          long total = dataSet.isEmpty()
                                  ? 0
                                  : dataSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS).asInt();
                          Log.d("Steps ", String.valueOf(total));
                          steps = (int)total; //Trying to get steps here
                      }
                  })
                  .addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                          Log.d("Status", "Failure", e);
                      }
                  })
                  .addOnCompleteListener(new OnCompleteListener&lt;DataSet&gt;() {
                      @Override
                      public void onComplete(@NonNull Task&lt;DataSet&gt; task) {
                          Log.d("Status", "Complete");
  
                      }
                  });
  
      }
  </code></pre>
  
  <p>Ive been up and down the official documentation and StackOverflow. But it seems like google made big changes to the API last year and so most things are outdated, including google's own tutorials (posted in 2015). And a few places that have updated documentation provide snippets of code, and I have no idea how to use them or where to put them.</p>