首页 > 解决方案 > Google fit REST API 无法添加部分数据源

问题描述

我正在尝试添加特定的数据源,范围是

https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.activity.write

但是当我尝试这样做时。它返回给我一个错误

      {
        "reason": "invalidArgument", 
        "message": "Data type does not match well-known data type with the same name", 
        "domain": "global"
      }

我向这个 URL 发送 POST 请求 https://www.googleapis.com/fitness/v1/users/me/dataSources

这是我的请求正文

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

我使用 PHP/Laravel 作为一种语言,我使用 CURL 作为 http 请求库。有人能告诉我我做错了什么吗?某些范围已成功添加,但有些范围无法添加。

谷歌文档参考:https ://developers.google.com/fit/datatypes/activity?authuser=3

标签: phplaravelgoogle-apigoogle-api-php-clientgoogle-api-client

解决方案


根据文档,activity_type (您有错字)不是正确的字符串。com.google.activity.segment需要activity字段。

请参阅文档

因此,当它在 Google Fit API 测试控制台中返回预期的资源和 HTTP 200 时,这将起作用:

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

推荐阅读