【问题标题】:Google fit API add multiple data type based on scopeGoogle fit API 根据范围添加多种数据类型
【发布时间】:2020-07-14 20:29:06
【问题描述】:

我正在使用具有多个用户范围的 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

【问题讨论】:

  • 一个数据源只有一个数据类型。你根本做不到。
  • 好的,谢谢@AndyTurner先生

标签: json rest google-fit google-fit-api


【解决方案1】:

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

dataType.field[]

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

【讨论】:

  • 您是什么意思,先生?可以举个例子吗?
  • 如果是字段,name应该放在哪里?
  • 如果您想要一个命名空间名称,如 dataType,那么您将获得每个数据类型中的一个,而不是每个字段。在这种情况下,是的,您要执行的操作(我现在理解为将两个命名空间名称放在一个数据类型中)根据定义是不可能的。如果你想在同一个数据类型中保存不同的数据,那么你可以使用 field[].name 值,并且允许每个字段一个。
  • 这么简单我想要的东西是不可能的?对吗先生?所以我需要单独添加它们吗?
  • 对我来说就是这样。我将使用由包含它们的数据类型取消引用的字段重新架构。我想如果你必须有命名空间注册名称,那么你将不得不使用不同的数据类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多