TransWikia.com

Google fit API add multiple data type based on scope

Stack Overflow Asked by draw134 on November 4, 2021

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

One Answer

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.

Answered by dolphus333 on November 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP