How to generate Key to access Google Fit for OutSystems
In the last project that I’ve been, one of the requirements was to connect the app to Google Fit / Apple Health so that we could extract user info such as weight or step counter.
After a search on Forge, we found HealthPlugin that served our needs. We made the necessary steps to integrate the plugin until we came across with the following error: “User cancelled the dialogue”. On the plugin’s support page, it says explicitly that it is necessary to configure a Keystore and add it to Service Studio when generating the build, but it does not explain how to achieve that. This is how we have done it and you can also do it:
Step 1. Generate the key with Keytool
- Start by opening the Command Line with administrator permissions and fill the command “cd C:\Program Files(x86)\ Java\ jre1.8.0_241\bin”, the path to the bin folder inside Java folder.
- Then, Access Keytool by filling the following command line
- Finish generating the key by writing the next command line:
keytool -genkeypair –v -keystore <name of the key file>.jks -alias <alias name> -keyalg RSA -keysize 2048 -validity 10000. The extension of the file must be .jks
Tips:
- The password that is required must be defined by the user
- You must answer the questions to generate the key
- A new password is required for the alias (if you press Enter, the password will be the same as the key)
- The generated file is created inside the bin folder of the Java folder (you can move it to another folder to facilitate the access)
Step 2. Create an OAuth client ID Credential
- Navigate to https://console.developers.google.com/
2.1. Enable Fitness API
- Create or select an existing project by clicking on the selected area
- Go to Library, search for Fitness API and enable it
2.2. Create an OAuth consent screen
2.2.1. When the External type is the one that suits the application:
- Add the scopes needed to grant access to the application
- Add the Application Homepage link and Application Privacy Policy link in the Domain verification menu
2.3. Create a credential: OAuth client ID
- Go to the Credentials menu
- Select Create Credentials and choose OAuth client ID
- Fill the Application Type as Android
- Type a name to identify the key (Note that it can’t be the same that you have on the app)
- Access Keytool again through Command Line and execute the following command with the path for the key generated before: keytool -exportcert -keystore <path to the key> -list -v. On the following example, the key was on the Desktop directory
- The password that is required is the one defined before, when the key was generated
- Copy the SHA1 fingerprint that appears on the console
- Paste on the following field in the website
- The Package Name required in the previous image is the App Identifier on Service Studio that appears when generating the build