4

I'm trying to implement the Google Fit API into my android wearable application. I have followed the GoogleFitAPI online steps with registering for an OAuth ID.

When trying to connect, I get an invalid account error.

Do I need to enable the free trial within the developer api console, or is there another issue that is causing this?

mClient = new GoogleApiClient.Builder(this)
            .addApi(Fitness.API)
            .addScope(Fitness.SCOPE_ACTIVITY_READ)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
myanimal
  • 3,580
  • 26
  • 26
AliceOS
  • 53
  • 1
  • 4

2 Answers2

5

Actually the Fit API is available on Android Wear devices. But you still have to do the initial setup (Step 5) one time on a paired handheld device. Once you've logged in and displayed the consent screen on the phone, you can access the API from the watch. A recommendation would be to send the selected user account to the watch using the MessageAPI to avoid trying to connect to the API before the required information has been synced to the watch.

Please note that if you chose to access the API from the watch you will ONLY get data collected by the watch (data is synced from the watch to the phone and to the cloud, but not back to the watch).

An alternative solution is to fetch the fitness data from the phone and send it to the watch (again using the MessageAPI).

EDIT: As of Google Play Services 7.3.0 you can also use Fitness.HistoryApi.readDailyTotal() if you just want to get the daily total value. This doesn't require any authentication, but will also only give you data from the local device.

TofferJ
  • 4,678
  • 1
  • 37
  • 49
  • 3
    Thanks TofferJ. I was able to connect following your instructions. Here's a github sample in case someone finds this and is interested https://github.com/ColeMurray/WearableFitnessApiSample – AliceOS Feb 05 '15 at 22:03
  • i occur this error: com.google.android.gms.common.api.ApiException: 17: Error resolution was canceled by the user, original error message: INVALID_ACCOUNT: null – D T Mar 07 '18 at 04:20
  • D T: I suggest posting a new question. Make sure to include a description of what you've tried, and if possible some relevant code. – TofferJ Mar 07 '18 at 16:32
  • @D T Were you able to resolve the issue of 17: Error resolution was canceled by the user, original error message: INVALID_ACCOUNT: null – djreenykev Nov 10 '19 at 07:36
0

Google Fit APIs are not yet enabled on Android Wear devices. You can connect to Google Fit on the handheld device and use the Wearable Data Layer to send data across, but obviously that uses the sensors and requires the use of a handheld device.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443