1

I would like to get some technical help with the google fit rest Rest API.

I am making an app that requires access to the location information and as a response for my request I am getting this json.

{
  "access_token": "ya29.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 
  "scope": "https://www.googleapis.com/auth/fitness.activity.read https://www.googleapis.com/auth/fitness.location.write https://www.googleapis.com/auth/fitness.location.read https://www.googleapis.com/auth/fitness.body.read", 
  "token_type": "Bearer", 
  "expires_in": 3600, 
  "refresh_token": "1/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}

So using the access_token, I made the following request and it works

https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate

Request Body:

{
"startTimeMillis":1543682285000,
"endTimeMillis":1543941485000,
"aggregateBy: [
{ 
  "dataSourceId":"derived:com.google.calories.expended:com.google.android.gms:merge_calories_expended",
  "dataTypeName":"com.google.calories.expended"
}
],"bucketByTime":{"durationMillis":259200000}
}

And I do get a correct response

but when done with the following body (dataSourceId and dataTypeName changed)

{
"startTimeMillis":1543682283000,
"endTimeMillis":1543941483000,
"aggregateBy":[
{
  "dataSourceId":"derived:com.google.location.sample:com.google.android.gms:merge_location_samples",
  "dataTypeName":"com.google.location.sample"}
],"bucketByTime":{"durationMillis":259200000}
}

I got

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "No permission to read data for this private data source."
   }
  ],
  "code": 403,
  "message": "No permission to read data for this private data source."
 }
}

Also tried using all the fitness scopes(Read and Write):

 "scope": "https://www.googleapis.com/auth/fitness.activity.write
           https://www.googleapis.com/auth/fitness.blood_pressure.read
           https://www.googleapis.com/auth/fitness.blood_pressure.write
           https://www.googleapis.com/auth/fitness.reproductive_health.write
           https://www.googleapis.com/auth/fitness.activity.read
           https://www.googleapis.com/auth/fitness.reproductive_health.read
           https://www.googleapis.com/auth/fitness.nutrition.write
           https://www.googleapis.com/auth/fitness.body_temperature.write
           https://www.googleapis.com/auth/fitness.body_temperature.read
           https://www.googleapis.com/auth/fitness.nutrition.read
           https://www.googleapis.com/auth/fitness.oxygen_saturation.write
           https://www.googleapis.com/auth/fitness.body.write
           https://www.googleapis.com/auth/fitness.body.read
           https://www.googleapis.com/auth/fitness.oxygen_saturation.read
           https://www.googleapis.com/auth/fitness.blood_glucose.write
           https://www.googleapis.com/auth/fitness.location.write
           https://www.googleapis.com/auth/fitness.location.read
           https://www.googleapis.com/auth/fitness.blood_glucose.read"
MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65
Ricardo Garza V.
  • 899
  • 1
  • 11
  • 26
  • From the error that you have shared, it is most likely that the you are not entitled or verified to access the data source. Have you also tried to clear any proxy? Also, have you tried visiting the documentation for [Wear OS](https://developer.android.com/training/wearables/) by Android? – MαπμQμαπkγVπ.0 Dec 05 '18 at 11:11

1 Answers1

2

As part of Google's ongoing efforts to improve data privacy and security, we are updating the Google Fit API. In November 2018, we made changes to the way location samples can be read through the Fit API for Android and the Fit REST API.

Going forward, applications will only be able to read location samples that they have written to the platform. As the merge_location_samples stream is written internally by the Fit platform, it is no longer accessible to third-party developers.

If your application requires access to location, we encourage you to use the standard means for accessing location on a user's device (see here).

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
  • Is that true for all types of internal Fit platform data or only for location? I'm particularly interested in body sensors data availability. – artBCode Mar 07 '19 at 12:50
  • 1
    @artBCode body sensor types remain public. You should be able to read them with the appropriate OAuth scope. – Andy Turner Mar 07 '19 at 13:15
  • Thank you for your response, Andy. If I may: I'm building an app using the Google Fit API where I'm trying to get live sensor data. After getting the proper ID Client the app works fine on android phones. When I try to connect to the Sensors API on Wear OS 2.x I get the following error: "com.google.android.gms.common.api.ApiException: 17: API: Fitness.SENSORS_CLIENT is not available on this device." Do you think it might be permission related(WearOS specific)? The app even shows up as connected in the Google Fit app. – artBCode Mar 07 '19 at 14:27