Google Fit API Cannot add most of the scopes

Viewed 399

I am using the Google Fit REST API for our current project. We can add some of the data sources but there are some we cannot add. We already followed the documentations. Some of the request are returning this kind of error message (we even tried in their OAuth playground)

"error": {
    "status": "INVALID_ARGUMENT", 
    "message": "Data type does not match well-known data type with the same name", 
    "code": 400, 
    "errors": [
      {
        "reason": "invalidArgument", 
        "message": "Data type does not match well-known data type with the same name", 
        "domain": "global"
      }
    ]
  }

What we are trying to add is this data source which we already allow the permission scopes of

https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.activity.write
{
  "application": {
      "name": "PersonalPulse",
      "version": "1.0.0"
    },
    "dataType": {
      "name": "com.google.activity.exercise",
      "field": [
        {
          "name": "exercise",
          "format": "integer"
        },
        {
          "name": "repetitions",
          "format": "integer"
        },
        {
          "name": "resistance type",
          "format": "integer"
        },
        {
          "name": "resistance",
          "format": "floatPoint"
        },
        {
          "name": "duration",
          "format": "integer"
        }
      ]
    },
    "device": {
      "manufacturer": "browser",
      "model": "browser",
      "type": "unknown",
      "uid": "2",
      "version": "10"
    },
    "type": "derived"
}

We followed the instructions based on the documentations here https://developers.google.com/fit/datatypes/activity#workout

We are using PHP/Laravel framework for the fitness api and cURL for the http requests. If someone got an idea why we got the error please help. Thanks.

You can also try in the google playground here and paste the scopes https://developers.google.com/oauthplayground/

1 Answers

The first problem with your request is that you're passing in the exercise is an integer field, but the documentation says that you need to pass in one of an enumerated set of strings (I don't know why it says int there, but if you click the "Accepted values", you can see those definitely aren't integers...).

However, it would be easier if you didn't specify the fields at all. Simply specify the data type name:

// ...
"dataType": {
  "name": "com.google.activity.exercise",
}
// ...

and the correct fields will be filled in on the backend and returned to you.

Related