0

I am trying to set up Google Fit API for a university project, however I have just noticed I am getting an error after choosing a Google log-in RESULT_CANCELED.

I have read some other forum pages and tried a few solutions:

  • Changing keystore to release mode, not debug
  • Changing dependencies
  • Changing keystore signing configs

Nothing is working for me! I have no idea what I am doing wrong so please ask me questions and I will be happy to help. I am aware I am using deprecated API functions however I cannot find anything more up to date that I understand how to implement.

Stack overflow answers researched:
Google Fit O Auth fails with RESULT_CANCELED without showing permission page
Google Oauth 2.0 RESULT_CANCELED while using Google Fit api

Builder

        mApiClient = new GoogleApiClient.Builder(this)
                .addApi(Fitness.SENSORS_API)
                .addApi(Fitness.RECORDING_API)
                .addApi(Fitness.HISTORY_API)
                .addApi(Fitness.SESSIONS_API)
                .addApi(Fitness.GOALS_API)
                .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

Method

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_OAUTH) {
        authInProgress = false;
        if (resultCode == RESULT_OK) {
            if (!mApiClient.isConnecting() && !mApiClient.isConnected()) {
                mApiClient.connect();
            }
        } else if (resultCode == RESULT_CANCELED) {
            Log.e("GoogleFit", "RESULT_CANCELED");
        }
    } else {
        Log.e("GoogleFit", "requestCode NOT request_oauth");
    }
}

Configs

  release {
        storeFile file("C:\\Program Files\\Java\\jdk1.8.0_144\\bin")
        storePassword "pw"
        keyAlias "release"
        keyPassword "pw"
    }
Caitlin
  • 531
  • 5
  • 19
  • To enable Google API you are required to enable Fitness API for your project and set-up OAuth Screen in Google Api console - https://console.developers.google.com/apis check if it is set up properly. – Shekhar Suman Jun 08 '21 at 23:09
  • Here is link to GIT repo for sample code on Google FIT android api. Hope this will help. link - https://developers.google.com/fit/android/samples – Shekhar Suman Jun 08 '21 at 23:13
  • My API is enabled and the OAuth is correctly set up with keystore credentials SHA1. The repo you have linked appears to be in Kotlin, I am using Java. – Caitlin Jun 09 '21 at 08:41
  • If your app is still being tested and built, check if you register your email to allow Google signin https://console.cloud.google.com/apis/credentials/consent?. Also check SHA-1 saved in the GCP, if it's debug then you need debug SHA-1 configured. – Arel Guatno Jun 06 '22 at 13:55

0 Answers0