4

我正在使用具有多个用户范围的 google fit API。如何为每个源添加多种数据类型。如果可能,为什么我不能将其添加为数据源。

{
   "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"
   }
}

我得到了回应

{
    "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"
    }
}

但是当我只添加一个像这样的范围时

{
   "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"
   }
}

它返回我 200,这是成功的。我错过了什么或者我正在尝试做的事情可能吗?谢谢。

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

4

1 回答 1

2

我相信您尝试做的嵌套必须在 dataField 级别而不是 dataType 级别。

数据类型.field[]

我认为这是因为我注意到 'field[]' 是一个集合,而 dataType 不是。

于 2020-07-07T12:35:16.447 回答