REST API 400 对空数据聚合 Activity 段的错误请求

REST API 400 Bad Request for Aggregated Activity Segments on Empty Data

我们正在通过 REST 接口为我们的用户请求 activity 按细分聚合的数据。 但是对于某些用户(不是全部),尽管共享相同的请求格式,但检索此数据失败并显示 400 Bad Request。

按段聚合的示例请求 JSON 是:

{
"aggregateBy": [
  {
    "dataTypeName": "com.google.activity.segment"
  },
  {
    "dataTypeName": "com.google.calories.expended"
  },
  {
    "dataTypeName": "com.google.step_count.delta"
  }
],
"bucketByActivitySegment": {
  "minDurationMillis": 60000
},
"startTimeMillis": 1627182120000,
"endTimeMillis": 1627268520000
}

对于所有记录了 activity 数据的用户,我们会收到带有数据点的成功响应,例如:

{
  "bucket": [
    {
      "startTimeMillis": "1627180684015",
      "endTimeMillis": "1627182139339",
      "dataset": [
        {
          "dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
          "point": [
            {
              "startTimeNanos": "1627180684015000000",
              "endTimeNanos": "1627182139339000000",
              "dataTypeName": "com.google.activity.summary",
              "originDataSourceId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
              "value": [
                {
                  "intVal": 7,
                  "mapVal": []
                },
                {
                  "intVal": 1455324,
                  "mapVal": []
                },
                {
                  "intVal": 1,
                  "mapVal": []
                }
              ]
            }
          ]
        },
[...]

但是对于没有记录 activity 数据的用户,我们总是会收到 400 Bad Request 响应,例如:

{
    "error": {
        "code": 400,
        "message": "unknown datasource: derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
        "errors": [
            {
                "message": "unknown datasource: derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
                "domain": "global",
                "reason": "invalidArgument"
            }
        ],
        "status": "INVALID_ARGUMENT"
    }
}

我们通过按时间汇总 activity 数据确认没有记录的 activity 数据,例如请求

{
"aggregateBy": [
  {
    "dataTypeName": "com.google.activity.segment"
  }
],
"bucketByTime": {
  "durationMillis": 60000
},
"startTimeMillis": 1627182120000,
"endTimeMillis": 1627268520000
}

导致带有完全空数据点的成功响应,例如:

{
    "bucket": [
        {
            "startTimeMillis": "1627182120000",
            "endTimeMillis": "1627182180000",
            "dataset": [
                {
                    "dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
                    "point": []
                }
            ]
        },
[...]
            "dataset": [
                {
                    "dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
                    "point": []
                }
            ]
        }
    ]
}

我们的问题是:

Google Fit 团队向我们确认,此响应行为不会改变,因为用户可能已经依赖它。我们需要解决这个问题,例如单独处理这个错误响应,检查数据是否为空或类似的东西。