4

I am using google fit API with multiple user scopes. How can I add multiple data type for each source. If possible, why I cannot add this as a datasource.

{
   "dataStreamName":"MyDataSource",
   "type":"derived",
   "application":{
      "detailsUrl":"http://example.com",
      "name":"Foo Example App",
      "version":"1"
   },
   "dataType":[
      {
    //1st data type
         "name":"com.google.step_count.delta",
         "field":[
            {
               "name":"steps",
               "format":"int"
            }
         ]
      },
      {
    //2nd data type
         "name":"com.google.calories.bmr",
         "field":[
            {
               "name":"calories",
               "format":"float"
            }
         ]
      }
   ],
   "device":{
      "manufacturer":"Example Manufacturer",
      "model":"ExampleTablet",
      "type":"tablet",
      "uid":"1000001",
      "version":"1.0"
   }
}

And I got a response of

{
    "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
        "errors": [
            {
                "message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
                "reason": "invalid"
            }
        ],
        "status": "INVALID_ARGUMENT"
    }
}

But when I only add one scope which is like this

{
   "dataStreamName":"MyDataSource",
   "type":"derived",
   "application":{
      "detailsUrl":"http://example.com",
      "name":"Foo Example App",
      "version":"1"
   },
   "dataType":{
         "name":"com.google.step_count.delta",
         "field":[
            {
               "name":"steps",
               "format":"integer"
            }
         ]
      },
   "device":{
      "manufacturer":"Example Manufacturer",
      "model":"ExampleTablet",
      "type":"tablet",
      "uid":"1000001",
      "version":"1.0"
   }
}

It returns me 200 which is successful. Did I miss something or is what I am trying to do possible? Thanks.

Google fit API reference https://developers.google.com/fit/rest/v1/reference/users/dataSources/create

draw134
  • 1,053
  • 4
  • 35
  • 84

1 Answers1

2

I believe the nesting your trying to do has to go at the dataField level rather than the dataType level.

dataType.field[]

I think this because I noticed that 'field[]' is a collection while dataType is not.

dolphus333
  • 1,232
  • 1
  • 13
  • 18
  • what do you mean sir? can you give me an example? – draw134 Jul 07 '20 at 12:36
  • if its the field, where should the `name` placed? – draw134 Jul 07 '20 at 12:38
  • If you want a namespaced name, as in dataType, then you get one of those per dataType, not per field. In that case, then yes, what you're trying to do, which I now understand to be placing two namespaced names in a single dataType, is impossible per the definition. If you want to hold different pieces of data within the same dataType, then you use the field[].name value, and are permitted one per field. – dolphus333 Jul 08 '20 at 01:26
  • so simply what i want is impossible to do? right sir? So i need to add them separately right? – draw134 Jul 08 '20 at 01:28
  • That's what it looks like to me. I'd re-architect using fields dereferenced by the dataType that contained them all. I guess if you have to have namespace registered names, then you're going to have to go with different dataTypes. – dolphus333 Jul 09 '20 at 02:09
  • okay sir thanks for the answer. I thought its possible to add them all – draw134 Jul 09 '20 at 02:11